# How to perform a pipeline aggregation without returning all buckets

**URL:** <https://discuss.elastic.co/t/how-to-perform-a-pipeline-aggregation-without-returning-all-buckets/166424>\
**Category:** Elasticsearch\
**Created:** [January 30, 2019, 8:10pm UTC](https://discuss.elastic.co/t/how-to-perform-a-pipeline-aggregation-without-returning-all-buckets/166424 "2019-01-30T20:10:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)\
**Post date:** [January 30, 2019, 8:10pm UTC](https://discuss.elastic.co/t/how-to-perform-a-pipeline-aggregation-without-returning-all-buckets/166424/1 "2019-01-30T20:10:12Z")

</div>

As question here [https://stackoverflow.com/questions/38081739/how-to-perform-a-pipeline-aggregation-without-returning-all-buckets-in-elasticse](https://stackoverflow.com/questions/38081739/how-to-perform-a-pipeline-aggregation-without-returning-all-buckets-in-elasticse)

Using a pipeline agg. to calculate average, I dont want to return all the bucket, just the result. I dont want to use filter because there are other agg.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [February 1, 2019, 1:35pm UTC](https://discuss.elastic.co/t/how-to-perform-a-pipeline-aggregation-without-returning-all-buckets/166424/2 "2019-02-01T13:35:03Z")

</div>

Your best bet is probably to use the `filter_path` [response filtering](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#common-options-response-filtering) option and just grab the parts your interested in. It's not perfect, since it will also return parts of the response you may not care about, but it'll let you trim the results a bit.

---

<div class="post-metadata">

**Author:** ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)\
**Post date:** [February 1, 2019, 2:51pm UTC](https://discuss.elastic.co/t/how-to-perform-a-pipeline-aggregation-without-returning-all-buckets/166424/3 "2019-02-01T14:51:44Z")

</div>

> [@ebuildy](#):
>
> I dont want to use filter because there are other agg

because the final query is generated. (maybe I could parse the final query and generate a filter\_path.... but I think this is a very important options with pipeline agg.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [February 1, 2019, 3:28pm UTC](https://discuss.elastic.co/t/how-to-perform-a-pipeline-aggregation-without-returning-all-buckets/166424/4 "2019-02-01T15:28:53Z")

</div>

You might be able to use the [bucket\_selector](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html) to prune out buckets you don't want, but you'll have to be careful that they are pruned after your other pipeline metrics are done being computed.

Otherwise, pipeline aggs mostly just "add" data to the results. Because pipeline aggs can operate on the results of other aggs and pipelines, and they can be chained together or multiple pipelines can operate on the same set of buckets, they only "add" to buckets otherwise they might destructively interfere with other operations. The exception is bucket\_selector, so you may be able to do what you want with that.

---

<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:** [March 1, 2019, 3:28pm UTC](https://discuss.elastic.co/t/how-to-perform-a-pipeline-aggregation-without-returning-all-buckets/166424/5 "2019-03-01T15:28:54Z")

</div>

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