# Must have all items in array query

**URL:** <https://discuss.elastic.co/t/must-have-all-items-in-array-query/305561>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [May 25, 2022, 6:25am UTC](https://discuss.elastic.co/t/must-have-all-items-in-array-query/305561 "2022-05-25T06:25:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amit4](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@Amit4](https://discuss.elastic.co/u/Amit4)\
**Post date:** [May 25, 2022, 6:25am UTC](https://discuss.elastic.co/t/must-have-all-items-in-array-query/305561/1 "2022-05-25T06:25:49Z")

</div>

Hello, i have the next document structure  
{  
id: 'offering\_1',  
qualification: ['11', '22']  
},  
{  
id: 'offering\_2',  
qualification: ['11', '22', '33']  
}

I wish to run a query that will return only records from index that **all the array items in the index** are part of the query array Example:

1. Query with values of 11 will return nothing
2. Query with values of 11,22 will return offering\_1
3. Query with values of 11,22,44 will return offering\_1
4. Query with values of 11,22,33 will return offering\_1 and offering\_2
5. Query with values of 11,22,33,44 will return offering\_1 and offering\_2

Is there anyway to query like this in elastic?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [May 25, 2022, 1:15pm UTC](https://discuss.elastic.co/t/must-have-all-items-in-array-query/305561/2 "2022-05-25T13:15:20Z")

</div>

Hi!

I believe there are a few ways to do this. Using the [Terms set query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-set-query.html) you will get the results you want.

```auto
GET idx_test/_search
{
  "query": {
    "terms_set": {
      "qualification": {
        "terms": [11,22,33,44],
        "minimum_should_match_field": "required_matches"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Amit4](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@Amit4](https://discuss.elastic.co/u/Amit4)\
**Post date:** [May 26, 2022, 8:02am UTC](https://discuss.elastic.co/t/must-have-all-items-in-array-query/305561/3 "2022-05-26T08:02:10Z")

</div>

> [@RabBit\_BR](#):
>
> ```auto
> {
> "query": {
> "terms_set": {
> "qualification": {
> "terms": [11,22,33,44],
> "minimum_should_match_field": "required_matches"
> }
> }
> }
> }
> 
> ```

Thanks a lot i have created the below records and used your query and it worked, thanks a lot 🙂  
{  
id: 'offering\_1',  
qualification: ['11', '22'],  
required\_matches: 2  
},  
{  
id: 'offering\_2',  
qualification: ['11', '22', '33'],  
required\_matches: 3  
}

---

<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:** [June 23, 2022, 8:02am UTC](https://discuss.elastic.co/t/must-have-all-items-in-array-query/305561/4 "2022-06-23T08:02:21Z")

</div>

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