[[query-dsl-geo-polygon-query]] === Geo-polygon query ++++ Geo-polygon ++++ deprecated::[7.12,Use <> instead where polygons are defined in GeoJSON or http://docs.opengeospatial.org/is/18-010r7/18-010r7.html[Well-Known Text (WKT)].] A query returning hits that only fall within a polygon of points. Here is an example: [source,console] -------------------------------------------------- GET /_search { "query": { "bool": { "must": { "match_all": {} }, "filter": { "geo_polygon": { "person.location": { "points": [ { "lat": 40, "lon": -70 }, { "lat": 30, "lon": -80 }, { "lat": 20, "lon": -90 } ] } } } } } } -------------------------------------------------- // TEST[warning:Deprecated field [geo_polygon] used, replaced by [[geo_shape] query where polygons are defined in geojson or wkt]] [discrete] ==== Query options [cols="<,<",options="header",] |======================================================================= |Option |Description |`_name` |Optional name field to identify the filter |`validation_method` |Set to `IGNORE_MALFORMED` to accept geo points with invalid latitude or longitude, `COERCE` to try and infer correct latitude or longitude, or `STRICT` (default is `STRICT`). |======================================================================= [discrete] ==== Allowed formats [discrete] ===== Lat long as array Format as `[lon, lat]` Note: the order of lon/lat here must conform with http://geojson.org/[GeoJSON]. [source,console] -------------------------------------------------- GET /_search { "query": { "bool": { "must": { "match_all": {} }, "filter": { "geo_polygon": { "person.location": { "points": [ [ -70, 40 ], [ -80, 30 ], [ -90, 20 ] ] } } } } } } -------------------------------------------------- // TEST[warning:Deprecated field [geo_polygon] used, replaced by [[geo_shape] query where polygons are defined in geojson or wkt]] [discrete] ===== Lat lon as string Format in `lat,lon`. [source,console] -------------------------------------------------- GET /_search { "query": { "bool": { "must": { "match_all": {} }, "filter": { "geo_polygon": { "person.location": { "points": [ "40, -70", "30, -80", "20, -90" ] } } } } } } -------------------------------------------------- // TEST[warning:Deprecated field [geo_polygon] used, replaced by [[geo_shape] query where polygons are defined in geojson or wkt]] [discrete] ===== Geohash [source,console] -------------------------------------------------- GET /_search { "query": { "bool": { "must": { "match_all": {} }, "filter": { "geo_polygon": { "person.location": { "points": [ "drn5x1g8cu2y", "30, -80", "20, -90" ] } } } } } } -------------------------------------------------- // TEST[warning:Deprecated field [geo_polygon] used, replaced by [[geo_shape] query where polygons are defined in geojson or wkt]] [discrete] ==== `geo_point` type The query *requires* the <> type to be set on the relevant field. [discrete] ==== Ignore unmapped When set to `true` the `ignore_unmapped` option will ignore an unmapped field and will not match any documents for this query. This can be useful when querying multiple indexes which might have different mappings. When set to `false` (the default value) the query will throw an exception if the field is not mapped.