Ajay Takur
Ajay Takur

Reputation: 6236

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

Upvotes: 1

Views: 43

Answers (1)

Val
Val

Reputation: 217474

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

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

Upvotes: 2

Related Questions