如何在ElasticSearch8.9 v中使用not子句获取具有过滤器上下文的文档

5gfr0r5j  于 11个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(114)
{
    "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"
                        }
                    }
                    
                }
            ]
        }
    }
 }
izj3ouym

izj3ouym1#

你只需要使用bool/must_not查询:

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

相关问题