2015-05-05 02:27:52 -04:00
|
|
|
[[query-dsl-geo-polygon-query]]
|
2015-06-03 19:59:22 -04:00
|
|
|
=== Geo Polygon Query
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-05-05 02:27:52 -04:00
|
|
|
A query allowing to include hits that only fall within a polygon of
|
2013-08-28 19:24:34 -04:00
|
|
|
points. Here is an example:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"geo_polygon" : {
|
|
|
|
"person.location" : {
|
|
|
|
"points" : [
|
|
|
|
{"lat" : 40, "lon" : -70},
|
|
|
|
{"lat" : 30, "lon" : -80},
|
|
|
|
{"lat" : 20, "lon" : -90}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2015-08-07 16:55:22 -04:00
|
|
|
[float]
|
|
|
|
==== Query Options
|
|
|
|
|
|
|
|
[cols="<,<",options="header",]
|
|
|
|
|=======================================================================
|
|
|
|
|Option |Description
|
|
|
|
|`_name` |Optional name field to identify the filter
|
|
|
|
|
|
|
|
|`coerce` |Set to `true` to normalize longitude and latitude values to a
|
|
|
|
standard -180:180 / -90:90 coordinate system. (default is `false`).
|
|
|
|
|
|
|
|
|`ignore_malformed` |Set to `true` to accept geo points with invalid latitude or
|
|
|
|
longitude (default is `false`).
|
2015-08-18 06:16:49 -04:00
|
|
|
|=======================================================================
|
2015-08-07 16:55:22 -04:00
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
[float]
|
2015-06-03 19:59:22 -04:00
|
|
|
==== Allowed Formats
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[float]
|
2015-06-03 19:59:22 -04:00
|
|
|
===== Lat Long as Array
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
Format in `[lon, lat]`, note, the order of lon/lat here in order to
|
|
|
|
conform with http://geojson.org/[GeoJSON].
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"geo_polygon" : {
|
|
|
|
"person.location" : {
|
|
|
|
"points" : [
|
|
|
|
[-70, 40],
|
|
|
|
[-80, 30],
|
|
|
|
[-90, 20]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[float]
|
2015-06-03 19:59:22 -04:00
|
|
|
===== Lat Lon as String
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
Format in `lat,lon`.
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"geo_polygon" : {
|
|
|
|
"person.location" : {
|
|
|
|
"points" : [
|
|
|
|
"40, -70",
|
|
|
|
"30, -80",
|
|
|
|
"20, -90"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[float]
|
2015-06-03 19:59:22 -04:00
|
|
|
===== Geohash
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"geo_polygon" : {
|
|
|
|
"person.location" : {
|
|
|
|
"points" : [
|
|
|
|
"drn5x1g8cu2y",
|
|
|
|
"30, -80",
|
|
|
|
"20, -90"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[float]
|
2015-06-03 19:59:22 -04:00
|
|
|
==== geo_point Type
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-08-06 11:24:29 -04:00
|
|
|
The query *requires* the <<geo-point,`geo_point`>> type to be set on the
|
|
|
|
relevant field.
|
2013-08-28 19:24:34 -04:00
|
|
|
|