# How to sub-group aggregated result in a bucket

**URL:** <https://discuss.elastic.co/t/how-to-sub-group-aggregated-result-in-a-bucket/27881>\
**Category:** Elasticsearch\
**Created:** [August 22, 2015, 8:12pm UTC](https://discuss.elastic.co/t/how-to-sub-group-aggregated-result-in-a-bucket/27881 "2015-08-22T20:12:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lekkie](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@lekkie](https://discuss.elastic.co/u/lekkie)\
**Post date:** [August 22, 2015, 8:12pm UTC](https://discuss.elastic.co/t/how-to-sub-group-aggregated-result-in-a-bucket/27881/1 "2015-08-22T20:12:01Z")

</div>

I will like to group an aggregated result into subgroups. E.g I want to group a document into host, inside the host bucket, I want to group into further buckets of service names, and then further subgroup into response code.

I was able to do a first level nested aggregation but I cant go another level.

Here is my aggregation query so far:

{  
"aggs": {  
"group\_by\_route": {  
"terms": {  
"field": "route",  
"size": 0,  
"order" : { "\_count" : "desc" }  
},  
"aggs": {  
"group\_by\_response\_code": {  
"terms": {  
"field": "consumerResponseCode",  
"size": 0,  
"order" : { "\_count" : "desc" }  
}  
}  
}  
}  
}  
}

---

<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:** [July 5, 2017, 11:54pm UTC](https://discuss.elastic.co/t/how-to-sub-group-aggregated-result-in-a-bucket/27881/2 "2017-07-05T23:54:23Z")

</div>


