2017-08-03 64 views
0

我正在將Elasticsearch實例從1.7升級到5.4.3,並且注意到兩個系統之間的搜索結果不同,即使使用相同的查詢。Elasticsearch查詢結果從1.7遷移到5.4時有所不同

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的第一個搜索結果將成爲第71屆結果Elasticsearch 5.4。當我用_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. 任何OB。在兩個版本中爲什麼我的搜索結果對於同等查詢會有如此不同?
  2. 是否事實_explain查詢Elasticsearch 1.7顯示比sum of進行計算更高max of,它是Elasticsearch 5.4 相反,表明了問題的一部分?

回答

0

默認 「相似性」 改變中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(最佳匹配25)。此更改將導致一組不同的結果,旨在成爲一組更好的搜索結果。

如果你想使用以前的行爲你可以改變映射文件​​使用classic(指TF/IDF)。例如,你的YAML映射文件可能有:

description: 
    type: text 
    similarity: classic 

更多信息,有用的鏈接: