# Must\_Not aggregation double counting items

**URL:** <https://discuss.elastic.co/t/must-not-aggregation-double-counting-items/209198>\
**Category:** Elasticsearch\
**Created:** [November 24, 2019, 7:41pm UTC](https://discuss.elastic.co/t/must-not-aggregation-double-counting-items/209198 "2019-11-24T19:41:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ad\_rip](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@ad\_rip](https://discuss.elastic.co/u/ad_rip)\
**Post date:** [November 24, 2019, 7:41pm UTC](https://discuss.elastic.co/t/must-not-aggregation-double-counting-items/209198/1 "2019-11-24T19:41:45Z")

</div>

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:

```auto
"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:

```auto
"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!

---

<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:** [December 22, 2019, 7:41pm UTC](https://discuss.elastic.co/t/must-not-aggregation-double-counting-items/209198/2 "2019-12-22T19:41:46Z")

</div>

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