# Matching by array elements

**URL:** <https://discuss.elastic.co/t/matching-by-array-elements/39530>\
**Category:** Elasticsearch\
**Created:** [January 19, 2016, 10:30am UTC](https://discuss.elastic.co/t/matching-by-array-elements/39530 "2016-01-19T10:30:11Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Alexey\_Danilov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexey_danilov/32/5995_2.png) [@Alexey\_Danilov](https://discuss.elastic.co/u/Alexey_Danilov)\
**Post date:** [January 19, 2016, 9:15pm UTC](https://discuss.elastic.co/t/matching-by-array-elements/39530/7 "2016-01-19T21:15:45Z")

</div>

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"] } } ]
        }
      }
    }
  }
}
```

---

_[View the full topic](https://discuss.elastic.co/t/matching-by-array-elements/39530)._
