# Nested aggregations not bringing any result

**URL:** <https://discuss.elastic.co/t/nested-aggregations-not-bringing-any-result/30028>\
**Category:** Elasticsearch\
**Created:** [September 25, 2015, 2:34pm UTC](https://discuss.elastic.co/t/nested-aggregations-not-bringing-any-result/30028 "2015-09-25T14:34:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tberne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tberne/32/648_2.png) [@tberne](https://discuss.elastic.co/u/tberne)\
**Post date:** [September 25, 2015, 2:34pm UTC](https://discuss.elastic.co/t/nested-aggregations-not-bringing-any-result/30028/1 "2015-09-25T14:34:06Z")

</div>

Hello,  
I'm working on an algorithm that will generate an Elasticsearch query. In this algorithm nested aggregations may be produced.  
In some cases, the nested aggregations does not produce any results.

Here's the sample mapping and data:

[http://pastebin.com/U9TaqxNJ](http://pastebin.com/U9TaqxNJ)

My algorithm is generating the following query:

[http://pastebin.com/tbJQaYQA](http://pastebin.com/tbJQaYQA)

The result is the following:

[http://pastebin.com/bcQ3Jwww](http://pastebin.com/bcQ3Jwww)

But I really think it should be something like:

[http://pastebin.com/QANGpSLE](http://pastebin.com/QANGpSLE)

The _sub2\_nested_ aggregation has 0 documents, but I think it should have 2 documents (_t1_ and _t2_).  
If I manually remove the _sub2\_nested_ aggregation (moving _sub2_ aggregation up) I can have the desired result.

The question is: does a nested aggregation mess up with another one?

Thanks!

---

<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:48pm UTC](https://discuss.elastic.co/t/nested-aggregations-not-bringing-any-result/30028/2 "2017-07-05T23:48:04Z")

</div>


