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 ...

Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.