How to fetch documents with must match clause in elastic search 8.9 v

37 Views Asked by At
{
    "size": 0,
    "query": {
        "bool": {
            "must": [
             {
                 "match": {
                     "cid": {
                         "query": "AFM"
                     }
                 }
             },
                {
                    "match": {
                        "web_code": "P" // how to write multiple codes here
                    }
                }
            ]
        }
    }
 }

The above is working fine for a single value. How to fetch with multiple web codes using must syntax..?

1

There are 1 best solutions below

6
Val On BEST ANSWER

You can do it with a terms query instead of match:

{
    "size": 0,
    "query": {
        "bool": {
            "must": [
                {
                    "terms": {
                        "web_code.keyword": ["P", "R", "S", "T"]
                    }
                }
            ]
        }
    }
 }