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

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 .

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.

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" }}

}

Hi @qub123

Try to use Terms query.

{
  "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

Could you show the mapping?

See Rollup job - should and minimum_should_match not working - #4 by Mark_Harwood

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