0

我有一个带有一个filter和一个must_not子句的布尔查询。但是当我执行查询时,我得到的结果包含must_not子句中指定的值。知道我做错了什么吗?

询问

POST /test/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "partnerId": {
              "value": 12345
            }
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "stage": {
              "value": "REJECTED"
            }
          }
        }
      ],
      "adjust_pure_negative": true
    }
  }
}

 

回复

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0,
    "hits": [
      {
        "_index": "test",
        "_type": "doc",
        "_id": "45678910",
        "_score": 0,
        "_source": {
          "id": 45678910,
          "partnerId": 12345,
          "stage": "REJECTED"
        }
      }
    ]
  }
}

映射

"mappings": {
      "doc": {
        "properties": {
          "id": {
            "type": "long"
          },
          "partnerId": {
            "type": "long"
          },
          "stage": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }

REJECTED请注意,即使我已将其包含在must_not子句中,在我的结果中我仍然获得了一个阶段。

弹性搜索版本:6.2.2

4

1 回答 1

-1

如果您正在使用字符串,您应该:

  • 对行字符串使用匹配
  • 将 term 与字符串中的关键字一起使用

您在官方文档中拥有所需的一切

匹配期限

要使用匹配:

GET /_search
{
"query": {
    "match" : {
        "message" : "this is a test"
        }
    }
}

使用术语:

POST _search
{
"query": {
    "term" : { "user" : "Kimchy" } 
    }
}

我希望我帮助了你

于 2018-04-10T07:26:55.457 回答