Ajay Takur
Ajay Takur

Reputation: 6236

How to fetch documents with filter context with not clause in elastic search 8.9 v

{
    "size": 0,
    "query": {
        "bool": {
            "must": [
             {
                 "match": {
                     "cid": {
                         "query": "AFM"
                     }
                 }
             },
                {
                    "match": {
                        "web_code": "P" 
                    }
                }
            ],
            "filter": [
                {
                     
                    "not": {  // "type": "parsing_exception","reason": "unknown query [not]"
                        "term": {
                            "web_code": "PS"
                        }
                    }
                    
                }
            ]
        }
    }
 }

Upvotes: 0

Views: 43

Answers (1)

Val
Val

Reputation: 217474

You simply need to use the bool/must_not query:

{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "cid": {
              "query": "AFM"
            }
          }
        },
        {
          "match": {
            "web_code.keyword": "P"
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "web_code.keyword": "PS"
          }
        }
      ]
    }
  }
}

Upvotes: 1

Related Questions