# Nested Filter & Nested Aggregation don't work together

**URL:** <https://discuss.elastic.co/t/nested-filter-nested-aggregation-dont-work-together/23368>\
**Category:** Elasticsearch\
**Created:** [April 22, 2015, 8:07pm UTC](https://discuss.elastic.co/t/nested-filter-nested-aggregation-dont-work-together/23368 "2015-04-22T20:07:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BradVido](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bradvido/32/741_2.png) [@BradVido](https://discuss.elastic.co/u/BradVido)\
**Post date:** [April 22, 2015, 8:07pm UTC](https://discuss.elastic.co/t/nested-filter-nested-aggregation-dont-work-together/23368/1 "2015-04-22T20:07:13Z")

</div>

Am I misunderstanding the Nested Filter? I expected it to exclude any  
nested objects that didn't match it (and subsequently not match them in any  
nested aggregations for the same path).

Example:  
I have a field "foo" with a mapping type of "nested".

I execute a mach-all query with a Nested Terms Filter where the field  
"foo.bar" is "value1".  
I also add a Nested terms aggregation on for the same field.

The problem is that the aggregation returns things other than "value1"!  
It will return "value2" if other nested objects in the same document had  
foo.bar=value1.

--  
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/b26d172f-38ab-4b6f-880c-053c12a2700f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b26d172f-38ab-4b6f-880c-053c12a2700f%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:18am UTC](https://discuss.elastic.co/t/nested-filter-nested-aggregation-dont-work-together/23368/2 "2017-07-06T00:18:12Z")

</div>


