Stats aggregation on latitude or longitude of a geo_point

Hi
I use geo_point data and I'd like to have stats aggregation on latitude.
like

      "aggs": {
        "lat": {
          "avg": {
            "field": "location.lat"
          }
        },

where location is a geo_point type.

It doesn't work. I succeeded using a script but it's slow. Any idea how to do that?
My current workaround is to also have a lat and lng field as double in my index. But it doesn't make sense to double the info.

Thanks
Seb

That's the best option IMO. You could also use a slower runtime field I believe.

You either use a script, which is expensive, or you store the points as doubles. The latter sounds more expensive, but it's probably not.

I guess you can use the geo_centroid aggregation as the latitude of the centroid should be equivalent to the latitude average. Of course you will be doing a bit more work as you are computing the average of the longitude too.

1 Like

geo_centroid looks a good approach to my use case! thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.