# Terms query from array with AND

**URL:** <https://discuss.elastic.co/t/terms-query-from-array-with-and/65792>\
**Category:** Elasticsearch\
**Created:** [November 11, 2016, 10:45am UTC](https://discuss.elastic.co/t/terms-query-from-array-with-and/65792 "2016-11-11T10:45:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![isaacpm](https://avatars.discourse-cdn.com/v4/letter/i/b9e5f3/32.png) [@isaacpm](https://discuss.elastic.co/u/isaacpm)\
**Post date:** [November 11, 2016, 10:45am UTC](https://discuss.elastic.co/t/terms-query-from-array-with-and/65792/1 "2016-11-11T10:45:25Z")

</div>

Hi,

what would be the best way to make the below terms query to AND the two fields in the array passed to the .raw field?  
At the moment if seems to be doing an OR between them:

{"sort" : [{ "\_score" : {"order" : "asc"}}],"query": {"bool" : {"filter" :{"bool": {"must":[{ "terms": {"categories.raw" : ["category2","category1"]}}, {"range": {"price": {"gte": 0,"lte": 250}}}]}}}},"from": 0, "size": 40}

Thanks,  
Isaac

---

<div class="post-metadata">

**Author:** ![isaacpm](https://avatars.discourse-cdn.com/v4/letter/i/b9e5f3/32.png) [@isaacpm](https://discuss.elastic.co/u/isaacpm)\
**Post date:** [November 11, 2016, 2:23pm UTC](https://discuss.elastic.co/t/terms-query-from-array-with-and/65792/3 "2016-11-11T14:23:20Z")

</div>

Are you sure it will make the terms query AND instead of the default OR?

---

<div class="post-metadata">

**Author:** ![drjz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drjz/32/972_2.png) [@drjz](https://discuss.elastic.co/u/drjz)\
**Post date:** [November 11, 2016, 2:38pm UTC](https://discuss.elastic.co/t/terms-query-from-array-with-and/65792/4 "2016-11-11T14:38:07Z")

</div>

My apologies, misread your question. Can you post an example of a document?

---

<div class="post-metadata">

**Author:** ![isaacpm](https://avatars.discourse-cdn.com/v4/letter/i/b9e5f3/32.png) [@isaacpm](https://discuss.elastic.co/u/isaacpm)\
**Post date:** [November 11, 2016, 2:40pm UTC](https://discuss.elastic.co/t/terms-query-from-array-with-and/65792/5 "2016-11-11T14:40:46Z")

</div>

sure,

{  
"name" : "name\_of\_the\_thing",  
"categories" : ["category1","category2"],  
"price": 10  
}

Thanks  
Isaac

---

<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:** [December 9, 2016, 2:40pm UTC](https://discuss.elastic.co/t/terms-query-from-array-with-and/65792/6 "2016-12-09T14:40:50Z")

</div>

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