# Perform a pipelines aggregation over the full set of potential buckets

**URL:** https://discuss.elastic.co/t/perform-a-pipelines-aggregation-over-the-full-set-of-potential-buckets/287097
**Category:** Elasticsearch
**Created:** [October 19, 2021, 1:38pm UTC](https://discuss.elastic.co/t/perform-a-pipelines-aggregation-over-the-full-set-of-potential-buckets/287097 "2021-10-19T13:38:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![seanletendre](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@seanletendre](https://discuss.elastic.co/u/seanletendre)
#### Post date: [October 19, 2021, 1:38pm UTC](https://discuss.elastic.co/t/perform-a-pipelines-aggregation-over-the-full-set-of-potential-buckets/287097/1 "2021-10-19T13:38:58Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 16, 2021, 1:39pm UTC](https://discuss.elastic.co/t/perform-a-pipelines-aggregation-over-the-full-set-of-potential-buckets/287097/2 "2021-11-16T13:39:44Z")

</div>

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