liveBook · Manning

Well-known text

As explained in Elasticsearch in Action, Second Edition

WKT, or Well-Known Text, is a text format for representing geometric objects and their coordinates.

Well-Known Text (WKT) is a text format for representing geometric objects and their coordinates. In Elasticsearch, it provides an alternative to GeoJSON for geo_shape values and can also represent geo_point locations. section 12.2.2 section 12.2.1

Common WKT uses in Elasticsearch include:

  • Representing a point as `POINT (0.17 51.57)` when indexing a cafe's geo_shape address. section 12.2.2
  • Representing a bounding box as `BBOX(0.08, 0.04, 52.00, 49.00)` in a geo_bounding_box query. section 12.4
  • Representing supported shapes such as points, multipoints, polygons, multipolygons, linestrings, and multilinestrings. section 12.2.2
  • Checking coordinate order carefully: WKT uses longitude followed by latitude, unlike comma-separated coordinate strings, which use latitude followed by longitude. section 12.2.2 section 12.4

Cafe location and bounding-box search

A cafe can store its address as `"POINT (0.17 51.57)"`. A search can then filter restaurant locations with `"wkt":"BBOX(0.08, 0.04, 52.00, 49.00)"`. The WKT value identifies the geometric form, while the numbers provide its coordinates. section 12.2.2 section 12.4

Listing 12.8 Geoquery with a location represented as WKT
GET restaurants/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ],
      "filter": [
        {
          "geo_bounding_box": {
            "location": {
              "wkt":"BBOX(0.08, 0.04, 52.00, 49.00)"    #1
            }
          }
        }
      ]
    }
  }
}

Inspect a complete Elasticsearch geo_bounding_box request using a WKT BBOX value. section 12.4

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines WKT, demonstrates POINT and BBOX syntax, lists shapes, and emphasizes coordinate order without detailing full geospatial search behavior.
Examples
Demonstrates POINT cafe locations, BBOX restaurant filters, and supported polygon, multipoint, and line shapes.
What you can do after
Apply it via Elasticsearch to encode geographic points, shapes, and bounding boxes in indexing and search requests.
How it connects
Links WKT with geo_shape, geo_point, GeoJSON, and geo_bounding_box queries.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.