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
