# Query must and must\_not

**URL:** <https://discuss.elastic.co/t/query-must-and-must-not/150976>\
**Category:** Elasticsearch\
**Created:** [October 4, 2018, 6:57am UTC](https://discuss.elastic.co/t/query-must-and-must-not/150976 "2018-10-04T06:57:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [October 4, 2018, 6:57am UTC](https://discuss.elastic.co/t/query-must-and-must-not/150976/1 "2018-10-04T06:57:01Z")

</div>

Hi All,

I am working on the below query and my perception of the output is that the domain.keyword produced by the must\_not is excluded from the output. Is that correct?

```
{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
                    "query": "source_affiliate:xxxx AND tags:cmgw AND action:P6* AND NOT action:*SPAM* AND _exists_:hdr_subject AND cm_score: [0 TO 90] AND NOT dkim:pass* AND NOT dmarc:pass* AND NOT hdr_subject.keyword:\"Mail delivery failed: returning message to sender\" AND NOT hdr_subject.keyword:\"Undelivered Mail Returned to Sender\"",
                    "analyze_wildcard": false
                  }
        }
      ],
      "must_not": [
        {
          "query_string": {
            "default_field": "domain.keyword", 
            "query": "cm_score:[100 TO 1000]"
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![fkelbert](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fkelbert/32/35762_2.png) [@fkelbert](https://discuss.elastic.co/u/fkelbert)\
**Post date:** [October 5, 2018, 4:59am UTC](https://discuss.elastic.co/t/query-must-and-must-not/150976/2 "2018-10-05T04:59:56Z")

</div>

Hi @pjanzen,

Any documents which match this query

```auto
          "query_string": {
            "default_field": "domain.keyword", 
            "query": "cm_score:[100 TO 1000]"
          }

```

will not be part of the result set.

See [Bool query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html).

---

<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:** [November 2, 2018, 5:00am UTC](https://discuss.elastic.co/t/query-must-and-must-not/150976/3 "2018-11-02T05:00:00Z")

</div>

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