# (newbie) Query elasticsearch as term query with multiple terms with AND and OR

**URL:** <https://discuss.elastic.co/t/newbie-query-elasticsearch-as-term-query-with-multiple-terms-with-and-and-or/155061>\
**Category:** Elasticsearch\
**Created:** [November 1, 2018, 6:41pm UTC](https://discuss.elastic.co/t/newbie-query-elasticsearch-as-term-query-with-multiple-terms-with-and-and-or/155061 "2018-11-01T18:41:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vchauras](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vchauras/32/37216_2.png) [@vchauras](https://discuss.elastic.co/u/vchauras)\
**Post date:** [November 1, 2018, 6:41pm UTC](https://discuss.elastic.co/t/newbie-query-elasticsearch-as-term-query-with-multiple-terms-with-and-and-or/155061/1 "2018-11-01T18:41:32Z")

</div>

I have a scenario where I want to get documents from elastic which have any one of the following text:

1- "samsung s8"  
2- "silverado"  
3- "rims"  
4- "ping pong"

As one can see here, "samsung s8/"ping pong" should have AND logic becoz i want both of those terms.

Is there a way to achieve this? Right now I form a elastic query like this which obviously is wrong since it can give result which have "s8" but not "samsung".

```
"must": [
        {
          "query_string": {
            "query": "samsung s8 silverado rims ping pong",
            "fields": [
              "category^1.0",
              "description^1.0",
              "keywords.*^0.0",
              "title^1.0"
            ],
            "use_dis_max": true,
            "tie_breaker": 0,
            "default_operator": "or",
            "auto_generate_phrase_queries": false,
            "max_determinized_states": 10000,
            "enable_position_increments": true,
            "fuzziness": "AUTO",
            "fuzzy_prefix_length": 0,
            "fuzzy_max_expansions": 50,
            "phrase_slop": 0,
            "escape": false,
            "split_on_whitespace": true,
            "boost": 1
          }
        }
      ],

```

Some help would be highly appreciated.

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [November 21, 2018, 9:59pm UTC](https://discuss.elastic.co/t/newbie-query-elasticsearch-as-term-query-with-multiple-terms-with-and-and-or/155061/2 "2018-11-21T21:59:54Z")

</div>

In `query_string` query, you can surround your query in double quotes to make it a phrase. Thus, if you are searching for phrases: "samsung s8" or "ping pong", your query could be:  
`"samsung s8" silverado rims "ping pong"`

---

<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 19, 2018, 10:14pm UTC](https://discuss.elastic.co/t/newbie-query-elasticsearch-as-term-query-with-multiple-terms-with-and-and-or/155061/3 "2018-12-19T22:14:17Z")

</div>

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