Elasticsearch查询返回奇怪的排序(基于分数)结果

时间:2017-09-03 15:51:51

标签: sorting elasticsearch n-gram scoring

我正在使用Elasticsearch v5.3.2

我有以下映射:

{
   "mappings":{
      "info":{
         "_all":{
            "enabled": false
         },
         "properties":{
            "info":{
               "properties":{
                  "email":{
                     "doc_values":"false",
                     "fields":{
                        "ngram":{
                           "analyzer":"custom_nGram_analyzer",
                           "type":"text"
                        }
                     },
                     "type":"keyword"
                  }
               }
            }
         }
     }
  },
  "settings":{
      "analysis":{
         "analyzer":{
             "custom_nGram_analyzer":{
                "filter":[
                   "lowercase",
                   "asciifolding",
                   "custom_nGram_filter"
                ],
                "tokenizer":"whitespace",
                "type":"custom"
            }
        },
        "filter":{
            "custom_nGram_filter":{
               "max_gram":16,
               "min_gram":3,
               "type":"ngram"
            }
        }
      }
   }
}

当我执行以下查询时,我在文档分数方面看到了非常奇怪的结果:

GET /info_2017_08/info/_search
{
  "query": {
      "multi_match": {
          "query": "hotmail",
          "fields": [
              "info.email.ngram"
          ]
      }
  }
}

它带来了以下结果:

"hits": {
    "total": 3,
    "max_score": 1.3834574,
    "hits": [
      {
        "_index": "info_2017_08",
        "_type": "info",
        "_id": "AV4uQnCjzNcTF2GMY730",
        "_score": 1.3834574,
        "_source": {
            "info": {
                 "email": "pv53p8vg@gmail.com"
             }
        }
     },
     {
        "_index": "info_2017_08",
        "_type": "info",
        "_id": "AV4uQm93zNcTF2GMY73x",
        "_score": 0.3967861,
        "_source": {
            "info": {            
                "email": "-vb6sbw54@hotmail.com"
            }
        }
     },
     {
         "_index": "info_2017_08",
         "_type": "info",
         "_id": "AV4uQmYbzNcTF2GMY73P",
         "_score": 0.36409757,
         "_source": {
             "info": {
                 "email": "985pu4c.r02a@gmail.com"
             }
         }
     }
  ]
}

现在注意分数。如果第一个结果是...... @ gmail.com而第二个结果是...... @ hotmail.com,如果我搜索了术语" hotmail& #34;

第二个应该与ngrams" mail"匹配查询。和#34; hotmail",而第一个只能通过ngram" mail"匹配查询,那么这样结果的原因是什么?

提前致谢。

1 个答案:

答案 0 :(得分:1)

Elasticsearch使用TF / IDF统计信息独立计算每个分片上的文档分数。因此,如果您有两个带有下一个内容的分片:

  1. “info.email”:“985pu4c.r02a@gmail.com”
  2. “info.email”:“1085pu4c.r02a@gmail.com”,“info.email”:“ - vb6sbw54 @ hotmail.com”
  3. 然后,对于您的特定查询,来自第一个分片的单个文档的分数将高于第二个分片中的任何文档。

    您可以使用下一个API调用检查每个分片的内容:GET index/_search?preference=_shards:0