Matching by array elements

Thanks, it is more clear now.

Am I right in understanding that "must_not" filter combined with array means that "none of the elements of the array should be present" in the document array, while "must" together with array translates to "any of the elements of the array should be present"? Somehow I could not find explanation of "must_not" filter in combination with arrays in documentation.

There is one other requirement which became clear recently - empty array in document should also be a match for any of the user input. Guess this means that "must" clause cannot be used anymore: "must": [ { "terms": { "array": [ "A", "B", "C" ] } } ] - but "must_not" alone should be quite sufficient, I guess. It will just have to operate on a larger document set.

Unless there is a way to match an empty array.

{
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "should": [
            { "missing": {"field": "array"} },
            { "terms": { "array": [ "A", "B", "C" ] } }
           ],
          "must_not": [ { "terms": { "array": [ "D", "E", "F", "G", "H", "I", "J", "K", "L" ] } } ]
        }
      }
    }
  }
}
2 Likes