【问题标题】:ElasticSearch must_not query return score=1 not 0ElasticSearch must_not 查询返回 score=1 而不是 0
【发布时间】:2019-03-21 19:01:26
【问题描述】:

我在official document找到了一些关于must_not的描述

must_not 子句(查询)不能出现在匹配的文档中。子句在过滤器上下文中执行,这意味着忽略评分并考虑缓存子句。由于忽略了评分,因此返回所有文档的 0 分数。

它告诉我 must_not 将返回 0 分数,就像 filter 操作一样。但是当我执行这个查询时:

GET /my_idx/my_type/_search
{
  "query": {
    "bool": {
      "must_not": [
        {"match" : {"name": "Test"}}
      ]
    }
  }
}

响应显示:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 6,
    "max_score": 1,
    "hits": [
      {
        "_index": "my_idx",
        "_type": "my_type",
        "_id": "Nbs5nmkBAfzcjFMf2czR",
        "_score": 1,
        "_source": {
          "analyzer": "my_tokenizer",
          "text": "Doe"
        }
      },
...

如您所见"_score": 1

为什么会这样?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    当您在过滤器中只有一个 must_not 时,会出现一个不可见的 match_all。你得到 _score = 1 的原因是什么。

    【讨论】:

    • 我使用"filter": {"match_all": {}},我得到了_score=0,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    相关资源
    最近更新 更多