Home > Net >  Elasticsearch Stats and Sum Aggregation under the hood
Elasticsearch Stats and Sum Aggregation under the hood

Time:06-02

I want to understand how elastic search works under the hood for stats aggregation and sum aggregation.

My use case needs date histogram aggregation as primary aggregation and sum aggregation or stat aggregation as the nested aggregation. I executed queries using both the aggregations on same amount of data in Kibana. And the time both the queries took for execution was similar. So, for all our use cases we might use stats aggregation all the time if there's no performance difference between stats & sum aggregation.

I couldn't find any detailed information about internal working of these aggregations. Request to provide me with any information on it or point me to any documentation describing how these aggregations work under the hood.

Elasticsearch version : 7.1

Thank You

CodePudding user response:

When in doubt, go to the source.

If you look at the implementation of StatsAggregator.java and SumAggregator.java, you'll see that they are very similar.

SumAggregator only computes a sum, while StatsAggregator computes sum, min, max, count and avg. Even though the latter seems to do more job, it is also only iterating once through the data in order to compute additional metrics, but those computations are not computationally expensive.

So if you know you need just the sum, use SumAggregator, but if you also need either min, max, count or avg, then go for StatsAggregator instead, so you only iterate once through the data.

  • Related