If I have customer locations stored as geo_point datatype (latitude/longitude) and i need to determine doc_count grouped by the geo_point location, what is the elasticsearch_dsl syntax?
1 Answers
Below query would give you what you need:
POST <your_index_name>/_search
{
"size":0,
"aggs":{
"myaggs":{
"terms":{
"script":"def x = String.valueOf(doc['location'].lat).concat(',')+ String.valueOf(doc['location'].lon); return x;"
}
}
}
}
Although I have the above query, I'd suggest you to rethink what your requirement is as geo-point aggregations would generally make sense only when you aggregate using range from a particular geo_point
for e.g. search gas stations which are near 100 miles around a house you have Amsterdam
.
You can then make use of aggregations that are specifically built to handle geo_point
datatype. I personally feel query I've provided, although works correctly, would not make any sense or I doubt if it would be of any help (although I hope it helps and I'm proved wrong).
Please go through the below links so that you would create aggregations for correct use-cases or at-least will make you rethink about your current use-case.
Geo Distance Aggregation and Geo Hash-grid Aggregation
Hope it helps!

- 8,547
- 2
- 22
- 32