0

Query is below

{
  "query": {
    "bool": {
      "must": {
        "query_string": {
          "query": "messi NOT barca AND psg",
          "fields": ["name^128"]
        }
      }
    }
  }
}

What is the difference in "query": "messi AND barca NOT psg"

What is order of precedence in AND, OR, NOT in DSL

Paulo
  • 8,690
  • 5
  • 20
  • 34
sim
  • 524
  • 3
  • 14

1 Answers1

1

TLDR;

As per the documentation

The familiar boolean operators AND, OR and NOT (also written &&, || and !) are also supported but beware that they do not honor the usual precedence rules, so parentheses should be used whenever multiple operators are used together.

Depending on what you want to need to set your parenthesis right.

To understand

messi NOT barca AND psg -> will match messi psg

messi AND barca NOT psg -> will match messi barca

messi NOT (barca AND psg) -> will match messi barca or messi psg but not messi barca psg

Paulo
  • 8,690
  • 5
  • 20
  • 34