| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 | [[query-dsl-geo-shape-query]]=== Geo-shape query++++<titleabbrev>Geo-shape</titleabbrev>++++Filter documents indexed using the `geo_shape` type.Requires the <<geo-shape,`geo_shape` Mapping>>.The `geo_shape` query uses the same grid square representation as the`geo_shape` mapping to find documents that have a shape that intersectswith the query shape. It will also use the same Prefix Tree configurationas defined for the field mapping.The query supports two ways of defining the query shape, either byproviding a whole shape definition, or by referencing the name of a shapepre-indexed in another index. Both formats are defined below withexamples.==== Inline Shape DefinitionSimilar to the `geo_shape` type, the `geo_shape` query useshttp://www.geojson.org[GeoJSON] to represent shapes.Given the following index:[source,js]--------------------------------------------------PUT /example{    "mappings": {        "properties": {            "location": {                "type": "geo_shape"            }        }    }}POST /example/_doc?refresh{    "name": "Wind & Wetter, Berlin, Germany",    "location": {        "type": "point",        "coordinates": [13.400544, 52.530286]    }}--------------------------------------------------// CONSOLE// TESTSETUPThe following query will find the point using the Elasticsearch's`envelope` GeoJSON extension:[source,js]--------------------------------------------------GET /example/_search{    "query":{        "bool": {            "must": {                "match_all": {}            },            "filter": {                "geo_shape": {                    "location": {                        "shape": {                            "type": "envelope",                            "coordinates" : [[13.0, 53.0], [14.0, 52.0]]                        },                        "relation": "within"                    }                }            }        }    }}--------------------------------------------------// CONSOLE==== Pre-Indexed ShapeThe Query also supports using a shape which has already been indexed inanother index. This is particularly useful for whenyou have a pre-defined list of shapes which are useful to yourapplication and you want to reference this using a logical name (forexample 'New Zealand') rather than having to provide their coordinateseach time. In this situation it is only necessary to provide:* `id` - The ID of the document that containing the pre-indexed shape.* `index` - Name of the index where the pre-indexed shape is. Defaultsto 'shapes'.* `path` - The field specified as path containing the pre-indexed shape.Defaults to 'shape'.* `routing` - The routing of the shape document if required.The following is an example of using the Filter with a pre-indexedshape:[source,js]--------------------------------------------------PUT /shapes{    "mappings": {        "properties": {            "location": {                "type": "geo_shape"            }        }    }}PUT /shapes/_doc/deu{    "location": {        "type": "envelope",        "coordinates" : [[13.0, 53.0], [14.0, 52.0]]    }}GET /example/_search{    "query": {        "bool": {            "filter": {                "geo_shape": {                    "location": {                        "indexed_shape": {                            "index": "shapes",                            "id": "deu",                            "path": "location"                        }                    }                }            }        }    }}--------------------------------------------------// CONSOLE==== Spatial RelationsThe <<spatial-strategy, geo_shape strategy>> mapping parameter determineswhich spatial relation operators may be used at search time.The following is a complete list of spatial relation operators available:* `INTERSECTS` - (default) Return all documents whose `geo_shape` fieldintersects the query geometry.* `DISJOINT` - Return all documents whose `geo_shape` fieldhas nothing in common with the query geometry.* `WITHIN` - Return all documents whose `geo_shape` fieldis within the query geometry.* `CONTAINS` - Return all documents whose `geo_shape` fieldcontains the query geometry. Note: this is only supported using the`recursive` Prefix Tree Strategy deprecated[6.6][float]==== Ignore UnmappedWhen set to `true` the `ignore_unmapped` option will ignore an unmapped fieldand will not match any documents for this query. This can be useful whenquerying multiple indexes which might have different mappings. When set to`false` (the default value) the query will throw an exception if the fieldis not mapped.
 |