elasticsearchelastic-stackelasticsearch-5elasticsearch-aggregationelasticsearch-dsl

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


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


Solution

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

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