Aggregation Filtering on Multiple Nested Objets

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
      }
    }
  }
}}}

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