# Aggregation Filtering on Multiple Nested Objets

**URL:** <https://discuss.elastic.co/t/aggregation-filtering-on-multiple-nested-objets/84074>\
**Category:** Elasticsearch\
**Created:** [April 29, 2017, 2:19am UTC](https://discuss.elastic.co/t/aggregation-filtering-on-multiple-nested-objets/84074 "2017-04-29T02:19:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![krmathieu](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@krmathieu](https://discuss.elastic.co/u/krmathieu)\
**Post date:** [April 29, 2017, 2:19am UTC](https://discuss.elastic.co/t/aggregation-filtering-on-multiple-nested-objets/84074/1 "2017-04-29T02:19:46Z")

</div>

I am trying to do an aggregation and use filters for multiple nested objects like below and the query runs, but the aggregation is not correct, it creates buckets for all segments.entities.types and not just those that begin with ORG. Basically, the filters have no effect on the aggregation at all as far as I can tell. Does anyone see what I am doing wrong? Any help would be appreciated. Thanks.

Kevin

```
{
 "size": 0,
 "aggs": {
        "filter_types": {
          "filter": {
            "bool": {
              "must": [ 
              {"nested": {"path": "disambigMismatches",
              	    "query": {
              	    "bool": {
              	    "must": [
            				{"exists": {"field": "disambigMismatches.mismatchText"}},
            				{"term": {"disambigMismatches.completeMismatch": true}}
            		]
            		}}}},
              {"nested": {"path": "segments",
              	    "query": {
              	    "bool": {
              	    "must": [
            				{"regexp": {"segments.entities.type": "ORG.*"}}
            		]
            		}}}}
              ]
            }
          },
		  "aggs":{
    		"entity_type_aggs":{
    			"terms": {
        			"field": "segments.entities.type",
        			"size": 50
      }
    }
  }
}}}
```

---

<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:** [May 27, 2017, 2:25am UTC](https://discuss.elastic.co/t/aggregation-filtering-on-multiple-nested-objets/84074/2 "2017-05-27T02:25:12Z")

</div>

Closed on May 27, 2017, 2:25am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
