| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 | [[query-dsl-shape-query]][role="xpack"][testenv="basic"]=== Shape query++++<titleabbrev>Shape</titleabbrev>++++Queries documents that contain fields indexed using the `shape` type.Requires the <<shape,`shape` Mapping>>.The query supports two ways of defining the target shape, either byproviding a whole shape definition, or by referencing the name, or id, of a shapepre-indexed in another index. Both formats are defined below withexamples.==== Inline Shape DefinitionSimilar to the `geo_shape` query, the `shape` query useshttp://www.geojson.org[GeoJSON] orhttps://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry[Well Known Text](WKT) to represent shapes.Given the following index:[source,console]--------------------------------------------------PUT /example{    "mappings": {        "properties": {            "geometry": {                "type": "shape"            }        }    }}POST /example/_doc?refresh{    "name": "Lucky Landing",    "location": {        "type": "point",        "coordinates": [1355.400544, 5255.530286]    }}--------------------------------------------------// TESTSETUPThe following query will find the point using the Elasticsearch's`envelope` GeoJSON extension:[source,console]--------------------------------------------------GET /example/_search{    "query":{        "shape": {            "geometry": {                "shape": {                    "type": "envelope",                    "coordinates" : [[1355.0, 5355.0], [1400.0, 5200.0]]                },                "relation": "within"            }        }    }}--------------------------------------------------==== 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,console]--------------------------------------------------PUT /shapes{    "mappings": {        "properties": {            "geometry": {                "type": "shape"            }        }    }}PUT /shapes/_doc/footprint{    "geometry": {        "type": "envelope",        "coordinates" : [[1355.0, 5355.0], [1400.0, 5200.0]]    }}GET /example/_search{    "query": {        "shape": {            "geometry": {                "indexed_shape": {                    "index": "shapes",                    "id": "footprint",                    "path": "geometry"                }            }        }    }}--------------------------------------------------==== Spatial RelationsThe 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.[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.
 |