Using a geo polygon filter
The previous recipe, Using a geo bounding box filter, shows you how to filter on a square section, which is the most common case. ElasticSearch provides a way to filter user-defined polygonal shapes via the geo_polygon
filter. This filter is useful if the filter is based on a country/region/district shape.
Getting ready
You need a working ElasticSearch cluster and an index populated with the GeoScript chapter_05/geo/populate_geo.sh
, available in the code bundle for this book.
How to do it...
Search for documents in which pin.location
is part of a triangle (a shape made up of three geopoints), as follows:
curl -XGET http://127.0.0.1:9200/test-mindex/_search?pretty -d '{ "query": { "filtered": { "filter": { "geo_polygon" { "pin.location": { "points": [ { "lat": 50, "lon": -30 }, { "lat": 30, "lon": -80 }, ...