| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 | [[query-dsl-geo-polygon-query]]=== Geo Polygon QueryA query allowing to include hits that only fall within a polygon ofpoints. Here is an example:[source,js]--------------------------------------------------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}                        ]                    }                }            }        }    }}--------------------------------------------------// CONSOLE[float]==== 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 withinvalid latitude or longitude, `COERCE` to try and infer correct latitudeor longitude, or `STRICT` (default is `STRICT`).|=======================================================================[float]==== Allowed Formats[float]===== Lat Long as ArrayFormat in `[lon, lat]`, note, the order of lon/lat here in order toconform with http://geojson.org/[GeoJSON].[source,js]--------------------------------------------------GET /_search{    "query": {        "bool" : {            "must" : {                "match_all" : {}            },            "filter" : {                "geo_polygon" : {                    "person.location" : {                        "points" : [                            [-70, 40],                            [-80, 30],                            [-90, 20]                        ]                    }                }            }        }    }}--------------------------------------------------// CONSOLE[float]===== Lat Lon as StringFormat in `lat,lon`.[source,js]--------------------------------------------------GET /_search{    "query": {        "bool" : {            "must" : {                "match_all" : {}            },            "filter" : {               "geo_polygon" : {                    "person.location" : {                        "points" : [                            "40, -70",                            "30, -80",                            "20, -90"                        ]                    }                }            }        }    }}--------------------------------------------------// CONSOLE[float]===== Geohash[source,js]--------------------------------------------------GET /_search{    "query": {        "bool" : {            "must" : {                "match_all" : {}            },            "filter" : {               "geo_polygon" : {                    "person.location" : {                        "points" : [                            "drn5x1g8cu2y",                            "30, -80",                            "20, -90"                        ]                    }                }            }        }    }}--------------------------------------------------// CONSOLE[float]==== geo_point TypeThe query *requires* the <<geo-point,`geo_point`>> type to be set on therelevant field.[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.
 |