# Multi word, single field AND query

**URL:** <https://discuss.elastic.co/t/multi-word-single-field-and-query/134898>\
**Category:** Elasticsearch\
**Created:** [June 7, 2018, 6:38am UTC](https://discuss.elastic.co/t/multi-word-single-field-and-query/134898 "2018-06-07T06:38:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fattyAtty](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@fattyAtty](https://discuss.elastic.co/u/fattyAtty)\
**Post date:** [June 7, 2018, 6:38am UTC](https://discuss.elastic.co/t/multi-word-single-field-and-query/134898/1 "2018-06-07T06:38:58Z")

</div>

Hi. I have a field TAGS that takes in a List of Strings. I want the user to specify the tags and the result should be records that contain at least all of the tags. For example, if she searches for A, B,C , i want the records like A,B,C,D or A,B,C to be returned but not records like A,B,D or A,B.

The TERMS QUERY ([https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-terms-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-terms-query.html)) would return A,B,D and A,B as well which i do not want.

I searched for an alternative way to do this ([https://www.elastic.co/guide/en/elasticsearch/guide/current/match-multi-word.html#match-multi-word](https://www.elastic.co/guide/en/elasticsearch/guide/current/match-multi-word.html#match-multi-word)) but that is basically searching for each tag separately and then performing an AND operation which seems sub-optimal.

I'm using ES 5.3. Could anyone present a better alternative? Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 7, 2018, 8:20am UTC](https://discuss.elastic.co/t/multi-word-single-field-and-query/134898/2 "2018-06-07T08:20:59Z")

</div>

If you are able to upgrade to version 6.2, you should be able to do this through the [terms set query](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-terms-set-query.html). If you cannot upgrade, a query requiring each term separately might be the best option.

---

<div class="post-metadata">

**Author:** ![fattyAtty](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@fattyAtty](https://discuss.elastic.co/u/fattyAtty)\
**Post date:** [June 14, 2018, 4:38am UTC](https://discuss.elastic.co/t/multi-word-single-field-and-query/134898/3 "2018-06-14T04:38:17Z")

</div>

Yes I'm aware of terms set query but I can't upgrade at this time. Thanks for your answer!

---

<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 12, 2018, 4:38am UTC](https://discuss.elastic.co/t/multi-word-single-field-and-query/134898/4 "2018-07-12T04:38:36Z")

</div>

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