# Sub Aggregating a terms Bucket Aggregation

**URL:** <https://discuss.elastic.co/t/sub-aggregating-a-terms-bucket-aggregation/284481>\
**Category:** Elasticsearch\
**Created:** [September 17, 2021, 12:31pm UTC](https://discuss.elastic.co/t/sub-aggregating-a-terms-bucket-aggregation/284481 "2021-09-17T12:31:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manisekhar\_techo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manisekhar_techo/32/78185_2.png) [@Manisekhar\_techo](https://discuss.elastic.co/u/Manisekhar_techo)\
**Post date:** [September 17, 2021, 12:31pm UTC](https://discuss.elastic.co/t/sub-aggregating-a-terms-bucket-aggregation/284481/1 "2021-09-17T12:31:07Z")

</div>

Hello,  
I have a bool Query which gives me results and terms bucket Aggregation on one of the Fields.  
is there a way to Aggregate each Bucket item with Date Histogram aggregation

```auto
{
    "size": 10,
    "query": {
        "bool": {
            "must": [
                {
                    "multi_match": {
                        "query": "welding",
                        "type": "phrase",
                        "fields": [
                            "title^10",
                            "abstraction"
                        ],
                        "boost": 25,
                        "_name": "welding"
                    }
                }
            ]
        }
    },
    "aggs": {
        "category": {
            "terms": {
                "field": "category",
                "size": 200
            },
            "aggs": {
                "dates": {
                    "date_histogram": {
                        "field": "pulbicationDate",
                        "interval": "year",
                        "format": "yyyy"
                    }
                }
            }
        }
    }
}

```

I was expecting aggregation results where I would have all the Category Buckets and Also the date Histogram of Each Category that's matching the Query.

Thank you.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 20, 2021, 7:54am UTC](https://discuss.elastic.co/t/sub-aggregating-a-terms-bucket-aggregation/284481/2 "2021-09-20T07:54:37Z")

</div>

Wasn't this answered in [Terms Bucket Aggregation count per Year](https://discuss.elastic.co/t/terms-bucket-aggregation-count-per-year/284487)?

---

<div class="post-metadata">

**Author:** ![Manisekhar\_techo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manisekhar_techo/32/78185_2.png) [@Manisekhar\_techo](https://discuss.elastic.co/u/Manisekhar_techo)\
**Post date:** [September 20, 2021, 8:08am UTC](https://discuss.elastic.co/t/sub-aggregating-a-terms-bucket-aggregation/284481/3 "2021-09-20T08:08:13Z")

</div>

Hi Mark. Yes that's the answer.  
Actually my question itself is the answer. It didn't work for me when I posted the question. So, I reposted it again with some changes (the post you are referring to )

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 20, 2021, 8:11am UTC](https://discuss.elastic.co/t/sub-aggregating-a-terms-bucket-aggregation/284481/4 "2021-09-20T08:11:31Z")

</div>

Ah ok, well it's good not to post the same thing more than once. It makes it harder to help 🙂

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 20, 2021, 8:11am UTC](https://discuss.elastic.co/t/sub-aggregating-a-terms-bucket-aggregation/284481/5 "2021-09-20T08:11:34Z")

</div>


