Must_Not aggregation double counting items

I'm hoping this is the right place to ask this. I've been trying to use a must_not filter to get a count of all the items that don't contain a contain a specific field, but unfortunately the count is much higher than the actual number of items that should be returned, and I think it's because it's counting the items multiple times.

The items have nested fields, as below:

"customFields": [
             {
                 "key": "firstType",
                 "keywordValue": "1"
             },
             {
                 "key": "secondType",
                 "keywordValue": "A"
             }
         ]

And I've been using the following query to find all the items without a second type, but the count return is much higher than it should be:

"aggregations": {
    "custom.secondType": {
      "filter": {
        "bool": {
          "must_not": [
            {
              "term": {
                "customFields.key": {
                  "value": "secondType",
                  "boost": 1.0
                }
              }
            }
          ],
          "adjust_pure_negative": true,
          "boost": 1.0
        }
      }
    }
  }
}

Is there an elasticsearch parameter that guarantees I won't be double counting that I've forgotten?

Thanks!

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