When using the _search
API of Elasticsearch, if you set size to 10, and perform an avg
metric aggregation, the average will be of all values across the dataset matching the query, not just the average of the 10 items returned in the hits
array.
On the other hand, if you perform a terms
aggregation and set the size
of the terms
aggregation to be 10, then performing an avg_buckets
aggregation on those terms
buckets will calculate an average over only those 10 buckets - not all potential buckets.
How can I calculate the an average of some field across all potential buckets, but still only have 10 items in the buckets
array?