'must_not' Clause

The 'must_not' clause specifies conditions that must not be satisfied for a document to be considered a match. In terms of logical operators, it corresponds to 'not' or 'and not' operators . The must_not clause is used when you want none of the specified conditions to be satisfied for a document to be considered a match.

Example -

Copy

{
  "query": {
    "bool": {
     "must": 
        { "term": { "Color": "Black" } },
      "must_not": [
        { "term": { "Bird": "Asian Koel" } },
        { "range": { "price": { "gte": 10} } },
        { "term": { "In Stock": "True" } }
      ]
    }
  }
}

In the above example, all candidates must satisfy the following condition:

  • exact match over the 'Color' field

All candidates must also not satisfy any of the three conditions -

  • exact match over the 'bird' field

  • The 'price' field must be less than 10

  • exact match over the "In Stock" field

Last updated