Use geo_shape when a location is more than one coordinate: a cafe can store a point, while a service area, route, or boundary can use lines and polygons. Elasticsearch indexes these shapes for focused geospatial search. section 12.1 section 12.2
A geo_shape field supports several GeoJSON and WKT representations:
- Point and MultiPoint represent one location or an array of locations. section 12.2.2
- LineString and MultiLineString represent lines or collections of lines. section 12.2.2
- Polygon and MultiPolygon represent multi-edge areas or collections of polygons. section 12.2.2
Mapping and indexing a cafe location
Create the field as geo_shape, then provide a GeoJSON point or WKT value: PUT cafes { "mappings": { "properties": { "name": { "type": "text" }, "address": { "type": "geo_shape" } } } } PUT cafes/_doc/1 { "name": "Costa Coffee", "address": { "type": "Point", "coordinates": [0.17, 51.57] } } PUT cafes/_doc/2 { "address": "POINT (0.17 51.57)" } GeoJSON requires a type and coordinates. GeoJSON and WKT place coordinates in longitude-latitude order; the string format uses latitude followed by longitude. section 12.2.2 section 12.2.2
Listing 12.4 Creating a mapping with the geo_shape field type
PUT cafes
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"address": {
"type": "geo_shape" #1
}
}
}
}
Inspect the complete cafe mapping that declares address as a geo_shape field. section 12.2.2
Listing 12.5 Inputting a geo_shape using WKT and GeoJSON formats
PUT cafes/_doc/1 #1
{
"name":"Costa Coffee",
"address" : {
"type" : "Point", #2
"coordinates" : [0.17, 51.57] #3
}
}
PUT /cafes/_doc/2 #4
{
"address" : "POINT (0.17 51.57)" #5
}
Compare runnable GeoJSON and WKT documents for indexing the same point-shaped location. section 12.2.2
