# Elastic search match Query string query (blue OR red OR yellow) AND cake

**URL:** <https://discuss.elastic.co/t/elastic-search-match-query-string-query-blue-or-red-or-yellow-and-cake/312704>\
**Category:** Elasticsearch\
**Created:** [August 23, 2022, 12:33pm UTC](https://discuss.elastic.co/t/elastic-search-match-query-string-query-blue-or-red-or-yellow-and-cake/312704 "2022-08-23T12:33:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![qub123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qub123/32/55327_2.png) [@qub123](https://discuss.elastic.co/u/qub123)\
**Post date:** [August 23, 2022, 12:33pm UTC](https://discuss.elastic.co/t/elastic-search-match-query-string-query-blue-or-red-or-yellow-and-cake/312704/1 "2022-08-23T12:33:41Z")

</div>

Hi,

I am trying to create a query to request all the "cake" with blue or red or yellow color, and I guess  
the condition similar to (blue OR red OR yellow) AND cake.  
And I have look at the Elasticsearch [Query String query documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html) .

But the result that return from my query below is everything about cake with also all the other colors that I didn't specify. But the result I want is cake which is only blue, red and yellow.

Just wondering can anyone point me my error, since I have been googling for few hours, and trying different thing. Still couldn't make it work.

```auto
GET /events_2022/_search
{
   "size":10,
  "query": {
      "bool": {
          "should": [     
            {"match": {"color": "blue"}},
            {"match": {"color": "red"}},
            {"match": {"color": "yellow"}}
          ],          
          "must": [     
            {"match": {"item": "cake"}}
          ]
      }
  },
    "aggs": {
      "group_by_eventType": {
        "terms": {
          "field": "color.keyword",
          "size" : 10000
        }
    }
  }
  ,
    "sort": { "eventTime": { "order": "desc" }}

}

```

---

<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:** [August 23, 2022, 12:38pm UTC](https://discuss.elastic.co/t/elastic-search-match-query-string-query-blue-or-red-or-yellow-and-cake/312704/2 "2022-08-23T12:38:19Z")

</div>

Hi @qub123

Try to use [Terms query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html#query-dsl-terms-query).

```auto
{
  "size": 10,
  "query": {
    "bool": {
      "filter": [
        {
          "terms": {
            "color.keyword": [
              "blue",
              "red",
              "yellow"
            ]
          }
        }
      ], 
      "must": [
        {
          "match": {
            "item": "cake"
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![qub123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qub123/32/55327_2.png) [@qub123](https://discuss.elastic.co/u/qub123)\
**Post date:** [August 23, 2022, 12:46pm UTC](https://discuss.elastic.co/t/elastic-search-match-query-string-query-blue-or-red-or-yellow-and-cake/312704/3 "2022-08-23T12:46:08Z")

</div>

> [@RabBit\_BR](#):
>
> ```auto
> {
> "size": 10,
> "query": {
> "bool": {
> "filter": [
> {
> "terms": {
> "color.keyword": [
> "blue",
> "red",
> "yellow"
> ]
> }
> }
> ], 
> "must": [
> {
> "match": {
> "item": "cake"
> }
> }
> ]
> }
> }
> 
> ```

Hi it didn't work, but I am sure we have data which is red cake, yellow cake, and blue cake. So it shouldn't return no data.

![image](https://us1.discourse-cdn.com/elastic/original/3X/2/c/2c66ea83f314c91b4357de8c689acbe953fa92fe.png)

---

<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:** [August 23, 2022, 12:57pm UTC](https://discuss.elastic.co/t/elastic-search-match-query-string-query-blue-or-red-or-yellow-and-cake/312704/4 "2022-08-23T12:57:48Z")

</div>

Could you show the mapping?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood1/32/101255_2.png) [@Mark\_Harwood1](https://discuss.elastic.co/u/Mark_Harwood1)\
**Post date:** [August 25, 2022, 8:13pm UTC](https://discuss.elastic.co/t/elastic-search-match-query-string-query-blue-or-red-or-yellow-and-cake/312704/5 "2022-08-25T20:13:27Z")

</div>

See [Rollup job - should and minimum\_should\_match not working - #4 by Mark\_Harwood](https://discuss.elastic.co/t/rollup-job-should-and-minimum-should-match-not-working/303829/4)

---

<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:** [September 22, 2022, 8:14pm UTC](https://discuss.elastic.co/t/elastic-search-match-query-string-query-blue-or-red-or-yellow-and-cake/312704/6 "2022-09-22T20:14:10Z")

</div>

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