I have following data - areas with boundingBoxCenter
geo_point
field and businesses with areaIds
array and location
geo_point
field.
For now I am aggregating them just by Terms
, by setting include
of areaIds
to the values I currently need. But there are too many areas next to each other on some map levels, so I would like to combine them based on density, e.g. 3 closest areas get merged based on dynamic precision.
I thought using GeohashGrid
as a subaggregation would do it, but I don't see a way to get the center points of TermsAggregation
without processing it by API first.
Is the problem solvable by Elastic in a single request with a combination of subaggregations by default? Or would I need to write some sort of a script or do the second part in API?
EDIT: also, ideally, I'd like to have results like this:
buckets { { doc_count: 47, subAggregation: { buckets: { { key: area_id, doc_count: 23, }, { key: another_area_id, doc_count: 24, } } } }, { doc_count: 90, subAggregation: { buckets: { ... } } } }
Or the other way round when it comes to main and sub aggregation. But any hints are very welcome.