Elasticsearch查询得分所有文档1.0。为什么?

时间:2016-10-18 16:59:20

标签: elasticsearch elasticsearch-2.0

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

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

查询:

{
    "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. 发出以下查询:

    {“query”:{“match”:{“last”:{“query”:“SMITHX”,fuzziness:1.0}}}}

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

    编辑2:看来我的复制步骤包括无意的谎言

    我的应用程序用来与elasticsearch(elastic4s)进行通信的库似乎会破坏查询,使其成为:

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

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

1 个答案:

答案 0 :(得分:1)

由于双查询关键字,这种情况正在发生。所以,基本上它是这样工作 - 内部查询选择命中并产生这样的东西:

{
    "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": ""
                }
            }
        ]
    }
}

这是完全正确的响应并且得分正确,但随后出现了第二个查询,这并没有改变结果集,但只有" eat"得分并将其替换为1.0。因此,您需要修复 elastic4s

的使用情况