Geo-polygon query
Geo-polygon query
Deprecated in 7.12.
Use Geoshape instead where polygons are defined in GeoJSON or Well-Known Text (WKT).
A query returning hits that only fall within a polygon of points. Here is an example:
resp = client.search(
query={
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"person.location": {
"points": [
{
"lat": 40,
"lon": -70
},
{
"lat": 30,
"lon": -80
},
{
"lat": 20,
"lon": -90
}
]
}
}
}
}
},
)
print(resp)
const response = await client.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.log(response);
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 }
]
}
}
}
}
}
}
Query options
Option | Description |
---|---|
| Optional name field to identify the filter |
| Set to |
Allowed formats
Lat long as array
Format as [lon, lat]
Note: the order of lon/lat here must conform with GeoJSON.
resp = client.search(
query={
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"person.location": {
"points": [
[
-70,
40
],
[
-80,
30
],
[
-90,
20
]
]
}
}
}
}
},
)
print(resp)
const response = await client.search({
query: {
bool: {
must: {
match_all: {},
},
filter: {
geo_polygon: {
"person.location": {
points: [
[-70, 40],
[-80, 30],
[-90, 20],
],
},
},
},
},
},
});
console.log(response);
GET /_search
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"person.location": {
"points": [
[ -70, 40 ],
[ -80, 30 ],
[ -90, 20 ]
]
}
}
}
}
}
}
Lat lon as string
Format in lat,lon
.
resp = client.search(
query={
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"person.location": {
"points": [
"40, -70",
"30, -80",
"20, -90"
]
}
}
}
}
},
)
print(resp)
const response = await client.search({
query: {
bool: {
must: {
match_all: {},
},
filter: {
geo_polygon: {
"person.location": {
points: ["40, -70", "30, -80", "20, -90"],
},
},
},
},
},
});
console.log(response);
GET /_search
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"person.location": {
"points": [
"40, -70",
"30, -80",
"20, -90"
]
}
}
}
}
}
}
Geohash
resp = client.search(
query={
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"person.location": {
"points": [
"drn5x1g8cu2y",
"30, -80",
"20, -90"
]
}
}
}
}
},
)
print(resp)
const response = await client.search({
query: {
bool: {
must: {
match_all: {},
},
filter: {
geo_polygon: {
"person.location": {
points: ["drn5x1g8cu2y", "30, -80", "20, -90"],
},
},
},
},
},
});
console.log(response);
GET /_search
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"person.location": {
"points": [
"drn5x1g8cu2y",
"30, -80",
"20, -90"
]
}
}
}
}
}
}
geo_point
type
The query requires the geo_point type to be set on the relevant field.
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.