119 lines
2.5 KiB
Plaintext
119 lines
2.5 KiB
Plaintext
[[query-dsl-geo-polygon-query]]
|
|
== Geo Polygon Query
|
|
|
|
A query allowing to include hits that only fall within a polygon of
|
|
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}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[float]
|
|
=== Allowed Formats
|
|
|
|
[float]
|
|
==== Lat Long as Array
|
|
|
|
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]
|
|
==== Lat Lon as String
|
|
|
|
Format in `lat,lon`.
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{
|
|
"filtered" : {
|
|
"query" : {
|
|
"match_all" : {}
|
|
},
|
|
"filter" : {
|
|
"geo_polygon" : {
|
|
"person.location" : {
|
|
"points" : [
|
|
"40, -70",
|
|
"30, -80",
|
|
"20, -90"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[float]
|
|
==== Geohash
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{
|
|
"filtered" : {
|
|
"query" : {
|
|
"match_all" : {}
|
|
},
|
|
"filter" : {
|
|
"geo_polygon" : {
|
|
"person.location" : {
|
|
"points" : [
|
|
"drn5x1g8cu2y",
|
|
"30, -80",
|
|
"20, -90"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[float]
|
|
=== geo_point Type
|
|
|
|
The filter *requires* the
|
|
<<mapping-geo-point-type,geo_point>> type to be
|
|
set on the relevant field.
|
|
|