# Multilevel aggregation of terms when using nested objects

**URL:** <https://discuss.elastic.co/t/multilevel-aggregation-of-terms-when-using-nested-objects/21329>\
**Category:** Elasticsearch\
**Created:** [December 19, 2014, 11:03am UTC](https://discuss.elastic.co/t/multilevel-aggregation-of-terms-when-using-nested-objects/21329 "2014-12-19T11:03:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmg](https://avatars.discourse-cdn.com/v4/letter/l/ecccb3/32.png) [@lmg](https://discuss.elastic.co/u/lmg)\
**Post date:** [December 19, 2014, 11:03am UTC](https://discuss.elastic.co/t/multilevel-aggregation-of-terms-when-using-nested-objects/21329/1 "2014-12-19T11:03:37Z")

</div>

We have a document format where there are a lot of nested objects and wants  
to look at e.g. location / language distribution.

When performing a aggregation where we have 2 levels of nested objects we  
get data only from the first level but not from the second level, it is  
always 0 in count.

If we do a non nested + nested aggregation it works.

{  
"from": 0,  
"size": 0,  
"aggs": {  
"Provider": {  
"terms": {  
"field": "providerId",  
"size": 10,  
"order": {  
"\_count": "desc"  
}  
},  
"aggs": {  
"Locations": {  
"nested": {  
"path": "meta"  
},  
"aggs": {  
"filter": {  
"filter": {  
"term": {  
"meta.type": "locations"  
}  
},  
"aggs": {  
"Locations": {  
"terms": {  
"field": "meta.value",  
"size": 3,  
"order": {  
"\_count": "desc"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
},  
"query": {  
"query\_string": {  
"query": "barclays bank"  
}  
}  
}

If we do a nested + non nested aggregation it does not work.

{  
"from": 0,  
"size": 0,  
"aggs": {  
"Locations": {  
"nested": {  
"path": "meta"  
},  
"aggs": {  
"filter": {  
"filter": {  
"term": {  
"meta.type": "locations"  
}  
},  
"aggs": {  
"Locations": {  
"terms": {  
"field": "meta.value",  
"size": 10,  
"order": {  
"\_count": "desc"  
}  
},  
"aggs": {  
"Provider": {  
"terms": {  
"field": "providerId",  
"size": 3,  
"order": {  
"\_count": "desc"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
},  
"query": {  
"query\_string": {  
"query": "barclays bank"  
}  
}  
}

Is there something wrong with my query or is this an issue in elasticsearch?

--

Solid Media Group is a global provider of marketing services within social  
and digital media. With more than 60 employees and offices or partners in  
19 countries the Group is among the leading European providers, trusted by  
more than 11 000 corporations. _From Buzz to Business_ is our mission,  
helping our customers to easily and successfully engage, market, publish,  
monitor and manage activities across the digital and social media world.  
Being the European leader within online news-, social-media-, and  
web-monitoring services, we already monitor more than 52 000 news sources  
in 51 languages and 180 countries. We have more than 1,5 billion downloaded  
and indexed news articles on our servers, a number which increases with  
more than 1.5 million each day. Through our partners and integrated  
solutions more than 20 000 enterprises are finding and receiving market  
updates from our monitoring services every day.

Copyright © 2011-2014 | Solid Media Group | NO 967 771 067 MVA

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/91ca631f-36d0-4325-aa8f-5cce3d340006%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/91ca631f-36d0-4325-aa8f-5cce3d340006%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:42am UTC](https://discuss.elastic.co/t/multilevel-aggregation-of-terms-when-using-nested-objects/21329/2 "2017-07-06T00:42:43Z")

</div>


