# Testing a field against an array of choices

**URL:** <https://discuss.elastic.co/t/testing-a-field-against-an-array-of-choices/3310>\
**Category:** Elasticsearch\
**Created:** [September 7, 2010, 7:09pm UTC](https://discuss.elastic.co/t/testing-a-field-against-an-array-of-choices/3310 "2010-09-07T19:09:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei/32/2856_2.png) [@Andrei](https://discuss.elastic.co/u/Andrei)\
**Post date:** [September 7, 2010, 7:09pm UTC](https://discuss.elastic.co/t/testing-a-field-against-an-array-of-choices/3310/1 "2010-09-07T19:09:04Z")

</div>

What is the best way to test a field (not\_analyzed one) to see if it  
matches a given array of choices, similar to how SQL's IN clause  
works? So far, I've been able to do it via an OR'ed "field" query, but  
wonder if there is a more efficient method:

{ query:  
{ filtered:  
{ query:  
{ query\_string:  
{ query: 'coffee'  
, use\_dis\_max: true  
, default\_operator: 'AND'  
, fields: ['title', 'desc'] }  
}  
, filter:  
{ query:  
{ field:  
{ user: 'user1 OR user2 OR user3' }  
}  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei/32/2856_2.png) [@Andrei](https://discuss.elastic.co/u/Andrei)\
**Post date:** [September 7, 2010, 7:26pm UTC](https://discuss.elastic.co/t/testing-a-field-against-an-array-of-choices/3310/2 "2010-09-07T19:26:10Z")

</div>

Never mind, I found "terms" filter. 🙂

On Sep 7, 12:09 pm, Andrei [and...@zmievski.org](mailto:and...@zmievski.org) wrote:

> What is the best way to test a field (not\_analyzed one) to see if it  
> matches a given array of choices, similar to how SQL's IN clause  
> works? So far, I've been able to do it via an OR'ed "field" query, but  
> wonder if there is a more efficient method:
> 
> { query:  
> { filtered:  
> { query:  
> { query\_string:  
> { query: 'coffee'  
> , use\_dis\_max: true  
> , default\_operator: 'AND'  
> , fields: ['title', 'desc'] }  
> }  
> , filter:  
> { query:  
> { field:  
> { user: 'user1 OR user2 OR user3' }  
> }  
> }  
> }  
> }
> 
> }

---

<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:** [July 6, 2017, 4:19am UTC](https://discuss.elastic.co/t/testing-a-field-against-an-array-of-choices/3310/3 "2017-07-06T04:19:38Z")

</div>

Closed on July 6, 2017, 4:19am UTC


