# Combine multiple terms aggregation as a pipeline

**URL:** <https://discuss.elastic.co/t/combine-multiple-terms-aggregation-as-a-pipeline/220588>\
**Category:** Elasticsearch\
**Created:** [February 24, 2020, 8:18am UTC](https://discuss.elastic.co/t/combine-multiple-terms-aggregation-as-a-pipeline/220588 "2020-02-24T08:18:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fenster25](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fenster25/32/55546_2.png) [@fenster25](https://discuss.elastic.co/u/fenster25)\
**Post date:** [February 24, 2020, 8:18am UTC](https://discuss.elastic.co/t/combine-multiple-terms-aggregation-as-a-pipeline/220588/1 "2020-02-24T08:18:47Z")

</div>

Lets say I have two fields in my docs `location` and `projects`. I want a terms aggregation on locations first and then on each of the aggregated buckets run a terms aggregation on projects. Is this possible? I went through the docs but was unable to find a pipeline aggregation using terms

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 24, 2020, 8:59am UTC](https://discuss.elastic.co/t/combine-multiple-terms-aggregation-as-a-pipeline/220588/2 "2020-02-24T08:59:26Z")

</div>

Hey,

can you explain why you need a pipeline agg for this? This sounds like having a terms on the `location` first and then a inner aggregation on the `projects` so that you get aggregations per project-per location sounds like this already solved the problem.

What am I missing?

--Alex

---

<div class="post-metadata">

**Author:** ![fenster25](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fenster25/32/55546_2.png) [@fenster25](https://discuss.elastic.co/u/fenster25)\
**Post date:** [February 24, 2020, 9:01am UTC](https://discuss.elastic.co/t/combine-multiple-terms-aggregation-as-a-pipeline/220588/3 "2020-02-24T09:01:31Z")

</div>

Yes thats right, I shouldn't have used the term pipeline I guess sounds confusing but I thought since it project based aggreagtion will work on the output of location based agg so I thought I might need to use a pipeline for it.

---

<div class="post-metadata">

**Author:** ![fenster25](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fenster25/32/55546_2.png) [@fenster25](https://discuss.elastic.co/u/fenster25)\
**Post date:** [February 24, 2020, 9:42am UTC](https://discuss.elastic.co/t/combine-multiple-terms-aggregation-as-a-pipeline/220588/4 "2020-02-24T09:42:08Z")

</div>

@spinscale are successive terms aggregation possible?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 24, 2020, 9:46am UTC](https://discuss.elastic.co/t/combine-multiple-terms-aggregation-as-a-pipeline/220588/5 "2020-02-24T09:46:22Z")

</div>

Yes, take another closer look at the structure at [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html#\_structuring\_aggregations](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html#_structuring_aggregations)

There is also an example using the max aggregation in the terms agg docs, see [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html)

---

<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 23, 2020, 9:46am UTC](https://discuss.elastic.co/t/combine-multiple-terms-aggregation-as-a-pipeline/220588/6 "2020-03-23T09:46:25Z")

</div>

Closed on March 23, 2020, 9:46am UTC

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