Geo-aggregations
Sometimes searches may return too many results but you might be just interested in finding out how many documents exist in a particular range of a location. A simple example can be to see how many news events related to crime occurred in an area by plotting them on a map or by generating a heatmap cluster of the events on the map, as shown in the following image:
Elasticsearch offers both metric and bucket aggregations for geo_point fields.
Geo distance aggregation
Geo distance aggregation is an extension of range aggregation. It allows you to create buckets of documents based on specified ranges. Let's see how this can be done using an example.
Python example
query = { "aggs": { "news_hotspots": { "geo_distance": { "field": "location", "origin": "28.61, 77.23", "unit": "km", "distance_type": "plane", "ranges": [ { "to": 50 }, { "from": 50, "to": 200 }, { ...