Executing the geo distance aggregation
Among the other standard types that we have seen in previous aggregations, ElasticSearch allows executing aggregations against a geo point: geo distance aggregations. This is an evolution of the previously discussed range aggregations built to work on geo locations.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script (executing_geo_distance_aggregations.sh
) available at https://github.com/aparo/elasticsearch-cookbook-second-edition.
How to do it...
Using the position field available in documents, we will aggregate the other documents in four ranges:
Fewer than 10 kilometers
From 10 to 20 kilometers
From 20 to 50 kilometers
From 50 to 100 kilometers
Above 100 kilometers
To execute geo distance aggregations, we will perform the steps given as follows:
To achieve these goals, we will create a geo distance aggregation with a code similar to this one:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true...