【问题标题】:Elasticsearch query results different when moving from 1.7 to 5.4从 1.7 迁移到 5.4 时,Elasticsearch 查询结果不同
【发布时间】:2018-01-11 15:11:32
【问题描述】:

我正在将 Elasticsearch 实例从 1.7 升级到 5.4.3,并注意到两个系统之间的搜索结果不同,即使使用相同的查询也是如此。

Elasticsearch 1.7 查询

{
  "query": {
    "filtered": {
      "query": {
        "multi_match": {
          "query": "something",
          "fields": [
            "field1",
            "field2",
            "field3"
          ],
          "operator": "and"
        }
      }
    }
  }
}

Elasticsearch 5.4 查询

{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "something",
            "fields": [
              "field1",
              "field2",
              "field3"
            ],
            "operator": "and"
          }
        }
      ]
    }
  }
}

Elasticsearch 1.7 中的第 1 个搜索结果成为 Elasticsearch 5.4 中的第 71 个结果。当我使用_explain 端点查看 1.7 和 5.4 之间的相同搜索结果时,我发现评分的方式有所不同。此外,此查询包括搜索查询匹配的同义词。

解释 Elasticsearch 1.7

{
    "_index": "...",
    "_type": "...",
    "_id": "...",
    "matched": true,
    "explanation": {
        "value": 9.963562,
        "description": "max of:",
        "details": [
            {
                "value": 3.1413355,
                "description": "sum of:",
                "details": [
                    {
                        "value": 1.0609967,
                        "description": "weight(field1:something in 13) [PerFieldSimilarity], result of:",
                        "details": [
...remainder removed for brevity

解释 Elasticsearch 5.4

{
    "_index": "...",
    "_type": "...",
    "_id": "...",
    "matched": true,
    "explanation": {
        "value": 7.1987557,
        "description": "sum of:",
        "details": [
            {
                "value": 7.1987557,
                "description": "max of:",
                "details": [
                    {
                        "value": 6.659632,
                        "description": "weight(Synonym(field1:something field1:something2 field1:something3) in 113) [PerFieldSimilarity], result of:",
                        "details": [
...remainder removed for brevity

问题

  1. 对于两个版本中的等效查询,我的搜索结果会如此不同,有什么明显的原因吗?
  2. Elasticsearch 1.7 的_explain 查询显示max of 高于sum of 的计算结果,而它与Elasticsearch 5.4 的相反这一事实是否表明部分问题?

【问题讨论】:

    标签: elasticsearch elasticsearch-5 elasticsearch-2.0


    【解决方案1】:

    Elasticsearch 5.0 中的默认“相似度”从 TF/IDF 更改为 BM25

    从技术上讲,这实际上是迁移到 Lucene 6.2(Elasticsearch 5.0.0 的默认值)时发生的变化。

    Elasticsearch 5.0.0 Release Notes 包括以下行:

    将默认相似度更改为 BM25 #18948(问题:#18944)

    您可以阅读有关Elasticsearch similarity here 的更多信息。这就是两个字段相互比较的方式(尤其是那些具有“文本”映射的字段)。在 5.0.0 之前,默认相似度是 TF/IDF(词频,逆文档频率),后来改为 BM25(Best Match 25)。此更改将导致一组不同的结果,旨在成为一组更好的搜索结果。

    如果您想使用之前的行为,您可以将映射文件中的similarity 更改为使用classic(指的是TF/IDF)。例如,您的 YAML 映射文件可能有:

    description:
      type: text
      similarity: classic
    

    提供更多信息的有用链接:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-28
      • 1970-01-01
      • 2015-01-01
      • 2014-10-15
      • 1970-01-01
      相关资源
      最近更新 更多