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

标签 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”一词,那么第一个结果的得分会比第二个更高?

第二个查询应将查询与ngrams“mail”和“hotmail”匹配,而第一个查询将仅通过ngrams“mail”与查询匹配,那么产生这种结果的原因是什么?

提前致谢。

最佳答案

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

  • “info.email”:“985pu4c.r02a@gmail.com”
  • “info.email”:“1085pu4c.r02a@gmail.com”,“info.email”:“-vb6sbw54@hotmail.com”

  • 然后,对于您的特定查询,第一个分片中的单个文档将比第二个分片中的任何文档得分更高。

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

    关于sorting - Elasticsearch查询返回奇怪的排序(基于分数)结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46025204/

    相关文章:

    python - 按第一项对嵌套列表进行排序——itemgetter 没有做到这一点

    javascript - 如何在javascript中按时间对对象数组进行排序

    Python 排序 - 对象列表

    ElasticSearch VM 克隆 - master_not_found_exception,找到具有相同 id 但是不同节点实例的现有节点

    json - 在 Logstash 中,如何限制在 Elasticsearch 中转换为索引字段的日志中 JSON 属性的深度?

    python - 无法使用 xpath、lxml 从抓取的页面获取脚本标记的内容

    python - 类似于 "Generate n-grams from Pandas column while persisting another column"(未解决),但有值

    c++ - 在 Eclipse 中对 C++ 方法进行排序/按字母顺序排列(不在大纲中,在代码中)

    amazon-web-services - 为什么 AWS Elasticsearch Minimum free storage space metric 不同于 cat allocation api

    python - 使用 gensim 学习的打印二元组