# Reverse nested aggregation within nested filter aggregation fails

**URL:** https://discuss.elastic.co/t/reverse-nested-aggregation-within-nested-filter-aggregation-fails/21748
**Category:** Elasticsearch
**Created:** [January 21, 2015, 12:21pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-within-nested-filter-aggregation-fails/21748 "2015-01-21T12:21:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![selvinaz\_karahancer8](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@selvinaz\_karahancer8](https://discuss.elastic.co/u/selvinaz_karahancer8)
#### Post date: [January 21, 2015, 12:21pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-within-nested-filter-aggregation-fails/21748/1 "2015-01-21T12:21:03Z")

</div>

Hello,

I have to realize distinct data queries on data persisted in ElasticSearch.  
My data model looks like:

{"took":15,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":3,"max\_score":1.0,"hits":[{"\_index":"event\_index\_v\_0\_3","\_type":"EventBean","\_id":"o6tFCVGjS7mnyUV92d7tOQ","\_score":1.0,"\_source":{  
"severityLevel" : "SL\_EVENT",  
"source" : {  
"sourceId" : "1",  
"sourceType" : "VEHICLE",  
"description" : null,  
"mandator" : {  
"mandatorId" : "DEF",  
"mandatorName" : null,  
"priority" : null  
},  
"eventTime" : 1410768722000,  
"version" : "Version\_0\_1",  
"attributes" : [ {  
"paramKey" : "COURSE",  
"value" : "123"  
}, {  
"paramKey" : "DRIVERNO",  
"value" : "111"  
}, {  
"paramKey" : "LINE",  
"value" : "101"  
}, {  
"paramKey" : "gps\_x",  
"value" : "11111111"  
}, {  
"paramKey" : "gps\_y",  
"value" : "87654321"  
} ]  
}}  
where attributes are nested objects of EventBeans.  
Now I want to have all distinct values of mandatorId, LINE and gps\_x.  
The aggregationbuilder looks like:

"aggregations" : {  
"source.mandator.mandatorId" : {  
"terms" : {  
"field" : "source.mandator.mandatorId",  
"size" : 2147483647,  
"min\_doc\_count" : 1  
},  
"aggregations" : {  
"attributes" : {  
"nested" : {  
"path" : "attributes"  
},  
"aggregations" : {  
"gps\_x" : {  
"filter" : {  
"term" : {  
"attributes.paramKey" : "gps\_x"  
}  
},  
"aggregations" : {  
"gps\_x" : {  
"terms" : {  
"field" : "attributes.value",  
"size" : 2147483647,  
"order" : {  
"\_count" : "desc"  
}  
},  
"aggregations" : {  
"attributes" : {  
"reverse\_nested" : {  
"path" : "attributes"  
},  
"aggregations" : {  
"LINE" : {  
"filter" : {  
"term" : {  
"attributes.paramKey" : "LINE"  
}  
},  
"aggregations" : {  
"LINE" : {  
"terms" : {  
"field" : "attributes.value",  
"size" : 2147483647,  
"order" : {  
"\_count" : "desc"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

and the response looks like:

"aggregations" : {  
"source.mandator.mandatorId" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 0,  
"buckets" : [ {  
"key" : "def",  
"doc\_count" : 3,  
"attributes" : {  
"doc\_count" : 15,  
"gps\_x" : {  
"doc\_count" : 3,  
"gps\_x" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 0,  
"buckets" : [ {  
"key" : "11111111",  
"doc\_count" : 1,  
"attributes" : {  
"doc\_count" : 1,  
"LINE" : {  
"doc\_count" : 0,  
"LINE" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 0,  
"buckets" : []  
}  
}  
}  
}, {  
"key" : "22222222",  
"doc\_count" : 1,  
"attributes" : {  
"doc\_count" : 1,  
"LINE" : {  
"doc\_count" : 0,  
"LINE" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 0,  
"buckets" : []  
}  
}  
}  
}, {  
"key" : "33333333",  
"doc\_count" : 1,  
"attributes" : {  
"doc\_count" : 1,  
"LINE" : {  
"doc\_count" : 0,  
"LINE" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 0,  
"buckets" : []  
}  
}  
}  
} ]  
}  
}  
}  
} ]  
}  
}

The buckets of LINEs are empty, I am using reverse\_nested aggregation, but  
I think I am still in the filter of attributes.paramKey=gps\_x.  
How can I solve this problem?  
Anyone an idea?

Thank you for your help.

--  
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/50b5bd03-4305-4575-8399-f122d84c4b53%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/50b5bd03-4305-4575-8399-f122d84c4b53%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![selvinaz\_karahancer8](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@selvinaz\_karahancer8](https://discuss.elastic.co/u/selvinaz_karahancer8)
#### Post date: [January 22, 2015, 10:13am UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-within-nested-filter-aggregation-fails/21748/2 "2015-01-22T10:13:06Z")

</div>

I am using Elasticsearch 1.3.4.

Nobody has an idea why the buckets of LINES are empty?  
Is there another possibility to resolve this problem?

Am Mittwoch, 21. Januar 2015 13:21:04 UTC+1 schrieb Selvinaz  
Karahancer-Bouraga:

> Hello,
> 
> I have to realize distinct data queries on data persisted in Elasticsearch.  
> My data model looks like:
> 
> {"took":15,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":3,"max\_score":1.0,"hits":[{"\_index":"event\_index\_v\_0\_3","\_type":"EventBean","\_id":"o6tFCVGjS7mnyUV92d7tOQ","\_score":1.0,"\_source":{  
> "severityLevel" : "SL\_EVENT",  
> "source" : {  
> "sourceId" : "1",  
> "sourceType" : "VEHICLE",  
> "description" : null,  
> "mandator" : {  
> "mandatorId" : "DEF",  
> "mandatorName" : null,  
> "priority" : null  
> },  
> "eventTime" : 1410768722000,  
> "version" : "Version\_0\_1",  
> "attributes" : [ {  
> "paramKey" : "COURSE",  
> "value" : "123"  
> }, {  
> "paramKey" : "DRIVERNO",  
> "value" : "111"  
> }, {  
> "paramKey" : "LINE",  
> "value" : "101"  
> }, {  
> "paramKey" : "gps\_x",  
> "value" : "11111111"  
> }, {  
> "paramKey" : "gps\_y",  
> "value" : "87654321"  
> } ]  
> }}  
> where attributes are nested objects of EventBeans.  
> Now I want to have all distinct values of mandatorId, LINE and gps\_x.  
> The aggregationbuilder looks like:
> 
> "aggregations" : {  
> "source.mandator.mandatorId" : {  
> "terms" : {  
> "field" : "source.mandator.mandatorId",  
> "size" : 2147483647,  
> "min\_doc\_count" : 1  
> },  
> "aggregations" : {  
> "attributes" : {  
> "nested" : {  
> "path" : "attributes"  
> },  
> "aggregations" : {  
> "gps\_x" : {  
> "filter" : {  
> "term" : {  
> "attributes.paramKey" : "gps\_x"  
> }  
> },  
> "aggregations" : {  
> "gps\_x" : {  
> "terms" : {  
> "field" : "attributes.value",  
> "size" : 2147483647,  
> "order" : {  
> "\_count" : "desc"  
> }  
> },  
> "aggregations" : {  
> "attributes" : {  
> "reverse\_nested" : {  
> "path" : "attributes"  
> },  
> "aggregations" : {  
> "LINE" : {  
> "filter" : {  
> "term" : {  
> "attributes.paramKey" : "LINE"  
> }  
> },  
> "aggregations" : {  
> "LINE" : {  
> "terms" : {  
> "field" : "attributes.value",  
> "size" : 2147483647,  
> "order" : {  
> "\_count" : "desc"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> and the response looks like:
> 
> "aggregations" : {  
> "source.mandator.mandatorId" : {  
> "doc\_count\_error\_upper\_bound" : 0,  
> "sum\_other\_doc\_count" : 0,  
> "buckets" : [ {  
> "key" : "def",  
> "doc\_count" : 3,  
> "attributes" : {  
> "doc\_count" : 15,  
> "gps\_x" : {  
> "doc\_count" : 3,  
> "gps\_x" : {  
> "doc\_count\_error\_upper\_bound" : 0,  
> "sum\_other\_doc\_count" : 0,  
> "buckets" : [ {  
> "key" : "11111111",  
> "doc\_count" : 1,  
> "attributes" : {  
> "doc\_count" : 1,  
> "LINE" : {  
> "doc\_count" : 0,  
> "LINE" : {  
> "doc\_count\_error\_upper\_bound" : 0,  
> "sum\_other\_doc\_count" : 0,  
> "buckets" :   
> }  
> }  
> }  
> }, {  
> "key" : "22222222",  
> "doc\_count" : 1,  
> "attributes" : {  
> "doc\_count" : 1,  
> "LINE" : {  
> "doc\_count" : 0,  
> "LINE" : {  
> "doc\_count\_error\_upper\_bound" : 0,  
> "sum\_other\_doc\_count" : 0,  
> "buckets" :   
> }  
> }  
> }  
> }, {  
> "key" : "33333333",  
> "doc\_count" : 1,  
> "attributes" : {  
> "doc\_count" : 1,  
> "LINE" : {  
> "doc\_count" : 0,  
> "LINE" : {  
> "doc\_count\_error\_upper\_bound" : 0,  
> "sum\_other\_doc\_count" : 0,  
> "buckets" :   
> }  
> }  
> }  
> } ]  
> }  
> }  
> }  
> } ]  
> }  
> }
> 
> The buckets of LINEs are empty, I am using reverse\_nested aggregation, but  
> I think I am still in the filter of attributes.paramKey=gps\_x.  
> How can I solve this problem?  
> Anyone an idea?
> 
> Thank you for your help.

--  
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/04894ca8-28c8-4ca5-add9-4d4f79802ac9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/04894ca8-28c8-4ca5-add9-4d4f79802ac9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![masaru](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@masaru](https://discuss.elastic.co/u/masaru)
#### Post date: [January 23, 2015, 4:22am UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-within-nested-filter-aggregation-fails/21748/3 "2015-01-23T04:22:11Z")

</div>

Hi,

Not sure if it solves your issue but I think there are a few things to fix:

- “attributes" is under “source". nested aggregation’s “path” would be “source.attributes”. You’d need to update field names accordingly as well.
- reverse\_nested aggregation’s “path” would be empty since it’s joined back to root.
- nested aggregation is needed around “LINE” aggregation since you are in root level.

Masaru

On January 22, 2015 at 19:13:10, Selvinaz Karahancer-Bouraga ([selvinaz.karahancer84@gmail.com](mailto:selvinaz.karahancer84@gmail.com)) wrote:

> I am using Elasticsearch 1.3.4.
> 
> Nobody has an idea why the buckets of LINES are empty?  
> Is there another possibility to resolve this problem?
> 
> Am Mittwoch, 21. Januar 2015 13:21:04 UTC+1 schrieb Selvinaz  
> Karahancer-Bouraga:
> 
> > Hello,
> > 
> > I have to realize distinct data queries on data persisted in Elasticsearch.  
> > My data model looks like:
> > 
> > {"took":15,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":3,"max\_score":1.0,"hits":[{"\_index":"event\_index\_v\_0\_3","\_type":"EventBean","\_id":"o6tFCVGjS7mnyUV92d7tOQ","\_score":1.0,"\_source":{  
> > "severityLevel" : "SL\_EVENT",  
> > "source" : {  
> > "sourceId" : "1",  
> > "sourceType" : "VEHICLE",  
> > "description" : null,  
> > "mandator" : {  
> > "mandatorId" : "DEF",  
> > "mandatorName" : null,  
> > "priority" : null  
> > },  
> > "eventTime" : 1410768722000,  
> > "version" : "Version\_0\_1",  
> > "attributes" : [ {  
> > "paramKey" : "COURSE",  
> > "value" : "123"  
> > }, {  
> > "paramKey" : "DRIVERNO",  
> > "value" : "111"  
> > }, {  
> > "paramKey" : "LINE",  
> > "value" : "101"  
> > }, {  
> > "paramKey" : "gps\_x",  
> > "value" : "11111111"  
> > }, {  
> > "paramKey" : "gps\_y",  
> > "value" : "87654321"  
> > } ]  
> > }}  
> > where attributes are nested objects of EventBeans.  
> > Now I want to have all distinct values of mandatorId, LINE and gps\_x.  
> > The aggregationbuilder looks like:
> > 
> > "aggregations" : {  
> > "source.mandator.mandatorId" : {  
> > "terms" : {  
> > "field" : "source.mandator.mandatorId",  
> > "size" : 2147483647,  
> > "min\_doc\_count" : 1  
> > },  
> > "aggregations" : {  
> > "attributes" : {  
> > "nested" : {  
> > "path" : "attributes"  
> > },  
> > "aggregations" : {  
> > "gps\_x" : {  
> > "filter" : {  
> > "term" : {  
> > "attributes.paramKey" : "gps\_x"  
> > }  
> > },  
> > "aggregations" : {  
> > "gps\_x" : {  
> > "terms" : {  
> > "field" : "attributes.value",  
> > "size" : 2147483647,  
> > "order" : {  
> > "\_count" : "desc"  
> > }  
> > },  
> > "aggregations" : {  
> > "attributes" : {  
> > "reverse\_nested" : {  
> > "path" : "attributes"  
> > },  
> > "aggregations" : {  
> > "LINE" : {  
> > "filter" : {  
> > "term" : {  
> > "attributes.paramKey" : "LINE"  
> > }  
> > },  
> > "aggregations" : {  
> > "LINE" : {  
> > "terms" : {  
> > "field" : "attributes.value",  
> > "size" : 2147483647,  
> > "order" : {  
> > "\_count" : "desc"  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > and the response looks like:
> > 
> > "aggregations" : {  
> > "source.mandator.mandatorId" : {  
> > "doc\_count\_error\_upper\_bound" : 0,  
> > "sum\_other\_doc\_count" : 0,  
> > "buckets" : [ {  
> > "key" : "def",  
> > "doc\_count" : 3,  
> > "attributes" : {  
> > "doc\_count" : 15,  
> > "gps\_x" : {  
> > "doc\_count" : 3,  
> > "gps\_x" : {  
> > "doc\_count\_error\_upper\_bound" : 0,  
> > "sum\_other\_doc\_count" : 0,  
> > "buckets" : [ {  
> > "key" : "11111111",  
> > "doc\_count" : 1,  
> > "attributes" : {  
> > "doc\_count" : 1,  
> > "LINE" : {  
> > "doc\_count" : 0,  
> > "LINE" : {  
> > "doc\_count\_error\_upper\_bound" : 0,  
> > "sum\_other\_doc\_count" : 0,  
> > "buckets" :   
> > }  
> > }  
> > }  
> > }, {  
> > "key" : "22222222",  
> > "doc\_count" : 1,  
> > "attributes" : {  
> > "doc\_count" : 1,  
> > "LINE" : {  
> > "doc\_count" : 0,  
> > "LINE" : {  
> > "doc\_count\_error\_upper\_bound" : 0,  
> > "sum\_other\_doc\_count" : 0,  
> > "buckets" :   
> > }  
> > }  
> > }  
> > }, {  
> > "key" : "33333333",  
> > "doc\_count" : 1,  
> > "attributes" : {  
> > "doc\_count" : 1,  
> > "LINE" : {  
> > "doc\_count" : 0,  
> > "LINE" : {  
> > "doc\_count\_error\_upper\_bound" : 0,  
> > "sum\_other\_doc\_count" : 0,  
> > "buckets" :   
> > }  
> > }  
> > }  
> > } ]  
> > }  
> > }  
> > }  
> > } ]  
> > }  
> > }
> > 
> > The buckets of LINEs are empty, I am using reverse\_nested aggregation, but  
> > I think I am still in the filter of attributes.paramKey=gps\_x.  
> > How can I solve this problem?  
> > Anyone an idea?
> > 
> > Thank you for your help.
> 
> --  
> 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/04894ca8-28c8-4ca5-add9-4d4f79802ac9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/04894ca8-28c8-4ca5-add9-4d4f79802ac9%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/etPan.54c1ccb0.41a7c4c9.1877%40citra.local](https://groups.google.com/d/msgid/elasticsearch/etPan.54c1ccb0.41a7c4c9.1877%40citra.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![selvinaz\_karahancer8](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@selvinaz\_karahancer8](https://discuss.elastic.co/u/selvinaz_karahancer8)
#### Post date: [January 23, 2015, 9:28am UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-within-nested-filter-aggregation-fails/21748/4 "2015-01-23T09:28:15Z")

</div>

Hi Masaru,

the datamodel is correct, attributes are in the root element, thas was just  
a copy paste failure.  
But the reason why it fails was that the nested aggregation around “LINE”  
has missing.

Now I get the correct results.

Thank you soooo much 🙂

2015-01-23 5:22 GMT+01:00 Masaru Hasegawa [haniomasali@gmail.com](mailto:haniomasali@gmail.com):

> Hi,
> 
> Not sure if it solves your issue but I think there are a few things to fix:
> 
> - “attributes" is under “source". nested aggregation’s “path” would be  
> “source.attributes”. You’d need to update field names accordingly as well.
> - reverse\_nested aggregation’s “path” would be empty since it’s joined  
> back to root.
> - nested aggregation is needed around “LINE” aggregation since you are in  
> root level.
> 
> Masaru
> 
> On January 22, 2015 at 19:13:10, Selvinaz Karahancer-Bouraga (  
> [selvinaz.karahancer84@gmail.com](mailto:selvinaz.karahancer84@gmail.com)) wrote:
> 
> > I am using Elasticsearch 1.3.4.
> > 
> > Nobody has an idea why the buckets of LINES are empty?  
> > Is there another possibility to resolve this problem?
> > 
> > Am Mittwoch, 21. Januar 2015 13:21:04 UTC+1 schrieb Selvinaz  
> > Karahancer-Bouraga:
> > 
> > > Hello,
> > > 
> > > I have to realize distinct data queries on data persisted in  
> > > Elasticsearch.  
> > > My data model looks like:
> 
> {"took":15,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":3,"max\_score":1.0,"hits":[{"\_index":"event\_index\_v\_0\_3","\_type":"EventBean","\_id":"o6tFCVGjS7mnyUV92d7tOQ","\_score":1.0,"\_source":{
> 
> > > "severityLevel" : "SL\_EVENT",  
> > > "source" : {  
> > > "sourceId" : "1",  
> > > "sourceType" : "VEHICLE",  
> > > "description" : null,  
> > > "mandator" : {  
> > > "mandatorId" : "DEF",  
> > > "mandatorName" : null,  
> > > "priority" : null  
> > > },  
> > > "eventTime" : 1410768722000,  
> > > "version" : "Version\_0\_1",  
> > > "attributes" : [ {  
> > > "paramKey" : "COURSE",  
> > > "value" : "123"  
> > > }, {  
> > > "paramKey" : "DRIVERNO",  
> > > "value" : "111"  
> > > }, {  
> > > "paramKey" : "LINE",  
> > > "value" : "101"  
> > > }, {  
> > > "paramKey" : "gps\_x",  
> > > "value" : "11111111"  
> > > }, {  
> > > "paramKey" : "gps\_y",  
> > > "value" : "87654321"  
> > > } ]  
> > > }}  
> > > where attributes are nested objects of EventBeans.  
> > > Now I want to have all distinct values of mandatorId, LINE and gps\_x.  
> > > The aggregationbuilder looks like:
> > > 
> > > "aggregations" : {  
> > > "source.mandator.mandatorId" : {  
> > > "terms" : {  
> > > "field" : "source.mandator.mandatorId",  
> > > "size" : 2147483647,  
> > > "min\_doc\_count" : 1  
> > > },  
> > > "aggregations" : {  
> > > "attributes" : {  
> > > "nested" : {  
> > > "path" : "attributes"  
> > > },  
> > > "aggregations" : {  
> > > "gps\_x" : {  
> > > "filter" : {  
> > > "term" : {  
> > > "attributes.paramKey" : "gps\_x"  
> > > }  
> > > },  
> > > "aggregations" : {  
> > > "gps\_x" : {  
> > > "terms" : {  
> > > "field" : "attributes.value",  
> > > "size" : 2147483647,  
> > > "order" : {  
> > > "\_count" : "desc"  
> > > }  
> > > },  
> > > "aggregations" : {  
> > > "attributes" : {  
> > > "reverse\_nested" : {  
> > > "path" : "attributes"  
> > > },  
> > > "aggregations" : {  
> > > "LINE" : {  
> > > "filter" : {  
> > > "term" : {  
> > > "attributes.paramKey" : "LINE"  
> > > }  
> > > },  
> > > "aggregations" : {  
> > > "LINE" : {  
> > > "terms" : {  
> > > "field" : "attributes.value",  
> > > "size" : 2147483647,  
> > > "order" : {  
> > > "\_count" : "desc"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > and the response looks like:
> > > 
> > > "aggregations" : {  
> > > "source.mandator.mandatorId" : {  
> > > "doc\_count\_error\_upper\_bound" : 0,  
> > > "sum\_other\_doc\_count" : 0,  
> > > "buckets" : [ {  
> > > "key" : "def",  
> > > "doc\_count" : 3,  
> > > "attributes" : {  
> > > "doc\_count" : 15,  
> > > "gps\_x" : {  
> > > "doc\_count" : 3,  
> > > "gps\_x" : {  
> > > "doc\_count\_error\_upper\_bound" : 0,  
> > > "sum\_other\_doc\_count" : 0,  
> > > "buckets" : [ {  
> > > "key" : "11111111",  
> > > "doc\_count" : 1,  
> > > "attributes" : {  
> > > "doc\_count" : 1,  
> > > "LINE" : {  
> > > "doc\_count" : 0,  
> > > "LINE" : {  
> > > "doc\_count\_error\_upper\_bound" : 0,  
> > > "sum\_other\_doc\_count" : 0,  
> > > "buckets" :   
> > > }  
> > > }  
> > > }  
> > > }, {  
> > > "key" : "22222222",  
> > > "doc\_count" : 1,  
> > > "attributes" : {  
> > > "doc\_count" : 1,  
> > > "LINE" : {  
> > > "doc\_count" : 0,  
> > > "LINE" : {  
> > > "doc\_count\_error\_upper\_bound" : 0,  
> > > "sum\_other\_doc\_count" : 0,  
> > > "buckets" :   
> > > }  
> > > }  
> > > }  
> > > }, {  
> > > "key" : "33333333",  
> > > "doc\_count" : 1,  
> > > "attributes" : {  
> > > "doc\_count" : 1,  
> > > "LINE" : {  
> > > "doc\_count" : 0,  
> > > "LINE" : {  
> > > "doc\_count\_error\_upper\_bound" : 0,  
> > > "sum\_other\_doc\_count" : 0,  
> > > "buckets" :   
> > > }  
> > > }  
> > > }  
> > > } ]  
> > > }  
> > > }  
> > > }  
> > > } ]  
> > > }  
> > > }
> > > 
> > > The buckets of LINEs are empty, I am using reverse\_nested aggregation,  
> > > but  
> > > I think I am still in the filter of attributes.paramKey=gps\_x.  
> > > How can I solve this problem?  
> > > Anyone an idea?
> > > 
> > > Thank you for your help.
> > 
> > --  
> > 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/04894ca8-28c8-4ca5-add9-4d4f79802ac9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/04894ca8-28c8-4ca5-add9-4d4f79802ac9%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/XRJNtckzlmE/unsubscribe](https://groups.google.com/d/topic/elasticsearch/XRJNtckzlmE/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/etPan.54c1ccb0.41a7c4c9.1877%40citra.local](https://groups.google.com/d/msgid/elasticsearch/etPan.54c1ccb0.41a7c4c9.1877%40citra.local)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CALEQBoggDfU\_LZ\_8AetCEJTbWcPHDTDNwVm76HhKt7-v9aRxPg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALEQBoggDfU_LZ_8AetCEJTbWcPHDTDNwVm76HhKt7-v9aRxPg%40mail.gmail.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:37am UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-within-nested-filter-aggregation-fails/21748/5 "2017-07-06T00:37:06Z")

</div>


