【问题标题】:Elasticsearch query scores all documents 1.0. Why?Elasticsearch 查询对所有文档进行评分 1.0。为什么?
【发布时间】:2017-02-28 01:40:17
【问题描述】:

我正在使用 ElasticSearch 2.4.1。当我执行以下查询时,所有文档的评分均为 1.0。为什么?

如果我删除“布尔”并在一个字段上进行匹配,我会得到相同的行为。

查询:

{
    "query" : 
    {   
        "bool": {
            "must" : [
                {"match" : { "last" : { "query" :  "SMITH" , fuzziness: 2.0}} }
            ],
        "should" : [
            {"match" : {"first" :{ "query" :  "JOE", fuzziness: 1.0, boost: 99.0}}}
            ]
        }
    }
}

解释一场比赛给了我:

1.0 = sum of:
  1.0 = ConstantScore(+(last:1mith^0.8 last:1smith^0.8 last:4mith^0.8 last:amith^0.8 last:asmith^0.8 last:bsmith^0.8 last:csmith^0.8 last:dsmith^0.8 last:emith^0.8 last:esmith^0.8 last:fsmith^0.8 last:hmith^0.8 last:hsmith^0.8 last:imith^0.8 last:ismith^0.8 last:jmith^0.8 last:jsmith^0.8 last:ksmith^0.8 last:lsmith^0.8 last:msith^0.8 last:msmith^0.8 last:nsmith^0.8 last:omith^0.8 last:osmith^0.8 last:psmith^0.8 last:qsmith^0.8 last:rsmith^0.8 last:saith^0.8 last:samith^0.8 last:scmith^0.8 last:seith^0.8 last:shith^0.8 last:simith^0.8 last:simth^0.8 last:skith^0.8 last:slith^0.8 last:smaith^0.8 last:smath^0.8 last:smdith^0.8 last:smeth^0.8 last:smfith^0.8 last:smich^0.8 last:smidh^0.8 last:smidth^0.8 last:smieth^0.8 last:smigh^0.8 last:smiht^0.8 last:smiih^0.8 last:smiith^0.8 last:smith) (first:aoe^0.6666666 first:bjoe^0.6666666 first:boe^0.6666666 first:coe^0.6666666 first:djoe^0.6666666 first:doe^0.6666666 first:eoe^0.6666666 first:foe^0.6666666 first:goe^0.6666666 first:hoe^0.6666666 first:ioe^0.6666666 first:j0e^0.6666666 first:jae^0.6666666 first:jbe^0.6666666 first:jce^0.6666666 first:jee^0.6666666 first:jeo^0.6666666 first:jge^0.6666666 first:jhe^0.6666666 first:jhoe^0.6666666 first:jie^0.6666666 first:jioe^0.6666666 first:jke^0.6666666 first:jle^0.6666666 first:jme^0.6666666 first:jne^0.6666666 first:jnoe^0.6666666 first:joa^0.6666666 first:joae^0.6666666 first:job^0.6666666 first:jobe^0.6666666 first:joc^0.6666666 first:joce^0.6666666 first:jod^0.6666666 first:jode^0.6666666 first:joe first:joea^0.6666666 first:joeb^0.6666666 first:joec^0.6666666 first:joed^0.6666666 first:joee^0.6666666 first:joef^0.6666666 first:joeg^0.6666666 first:joeh^0.6666666 first:joei^0.6666666 first:joej^0.6666666 first:joek^0.6666666 first:joel^0.6666666 first:joem^0.6666666 first:joen^0.6666666)^99.0), product of:
    1.0 = boost
    1.0 = queryNorm
  0.0 = match on required clause, product of:
0.0 = # clause
0.0 = weight(_type:mytype in 327) [], result of:
  0.0 = score(doc=327,freq=1.0), with freq of:
    1.0 = termFreq=1.0

类型映射:

{
  "ourindex1": {
    "mappings": {
      "people": {
        "properties": {        
          "city": {
            "type": "string"
          },
          "first": {
            "type": "string"
          },
          "last": {
            "type": "string"
          },
          "middle": {
            "type": "string"
          },
         "state": {
            "type": "string"
          },
          "street": {
            "type": "string"
          },
          "suffix": {
            "type": "string"
          },
          "suite": {
            "type": "string"
          },
          "territory": {
            "type": "string"
          },
          "zip5": {
            "type": "string"
          }
        }
      }
    }
  }
}

编辑:简化复制:

  1. 下载干净版的elasticsearch 2.4.1并启动
  2. 使用以下命令创建新索引:

    POST /newindex/people

    {“first”:“JOE”,“last”:“SMITH”,“street”:“1 FIRST STREET”,“city”:“LOS ANGELES”,“state”:“CA”,“middle” : ""}

  3. 发出以下查询:

    {“查询”:{“匹配”:{“最后”:{“查询”:“SMITHX”,模糊性:1.0}}}}

当我这样做时,返回的文档得分为 1.0,并解释说有关 ConstantScore 的内容。

编辑 2:我的复制步骤似乎包含了一个无意的谎言

我的应用用于与 elasticsearch (elastic4s) 通信的库似乎会破坏查询,使其变为:

{"query" : { "query" : {"match" : { "last" : { "query" : "SMITHX", fuzziness: 1.0} } }}}

(请注意,额外的“查询”。这个损坏的查询返回我期望的结果,但 score = 1.0。)我以为我已经尝试过直接使用 curl 执行查询,但显然不是。

【问题讨论】:

  • 我尝试了相同的查询,似乎对我有用。你能发布一些你的数据吗?
  • @JianpingLiu 我添加了包含一些示例数据的复制步骤。

标签: elasticsearch elasticsearch-2.0


【解决方案1】:

这是由于双 query 关键字造成的。所以,基本上它是这样工作的 - 内部 query 选择命中并产生如下内容:

{
    "took": 7,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 0.30685285,
        "hits": [
            {
                "_index": "my_index",
                "_type": "people",
                "_id": "2",
                "_score": 0.30685285,
                "_source": {
                    "first": "JOHN",
                    "last": "SMITHS",
                    "street": "2 SECOND STREET",
                    "city": "LA",
                    "state": "CA",
                    "middle": ""
                }
            },
            {
                "_index": "my_index",
                "_type": "people",
                "_id": "1",
                "_score": 0.30685282,
                "_source": {
                    "first": "JOE",
                    "last": "SMITH",
                    "street": "1 FIRST STREET",
                    "city": "LOS ANGELES",
                    "state": "CA",
                    "middle": ""
                }
            }
        ]
    }
}

这是具有正确分数的完全正确响应,但随后出现第二个 查询,它没有更改结果集,而只是“吃掉”分数并将其替换为 1.0。所以,你需要修正你对 elastic4s

的使用

【讨论】:

  • 是的。以防万一有人通过谷歌到达这里:我在做search in ("index" -> type") rawQuery("{query: { bool : ... }}")我应该一直在做:search in ("index" -> "type") rawQuery("{bool:...}")
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-13
  • 1970-01-01
  • 2018-12-08
  • 2017-11-06
  • 1970-01-01
相关资源
最近更新 更多