Using the geo_polygon query
The Using the geo_bounding_box query recipe shows how to filter on the square section, which is the most common case; Elasticsearch provides a way to filter user-defined polygonal shapes via the geo_polygon
filter. This query is useful if the polygon represents a country/region/district shape.
Getting ready
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
To execute curl
via the command line, you need to install curl
for your operating system.
To correctly execute the following commands, you need an index populated with the chapter_07/populate_geo.sh
geoscript available in the online code.
How to do it...
To execute a geopolygon query, we will perform the following steps:
Searching documents in which
pin.location
is part of a triangle (its shape is madeup of three geopoints) is done with a similar query:curl -XGET "http://127.0.0.1:9200/test-mindex...