2017-10-11 85 views
1

在嵌套字段上運行匹配查詢時,是基於所有根文檔中的所有嵌套文檔計算的每個嵌套文檔的相關性分數,還是僅在單個根文檔下的嵌套文檔?基本上,當計算TF/IDF時,用於IDF的集合的範圍是什麼?如何在Elasticsearch中計算嵌套文檔相關性分數(TF/IDF)?

這裏是一個嵌套的文件:

PUT /channels_index 
{ 
    "mappings": { 
    "channel": { 
     "properties": { 
     "username": { "type": "string" }, 
     "posts": { 
      "type": "nested", 
      "properties": { 
      "link": { "type": "string" }, 
      "caption": { "type": "string" }, 
      } 
     } 
     } 
    } 
    } 
} 

這裏是查詢:

GET channels/_search 
{ 
    "query": { 
    "nested": { 
     "path": "posts", 
     "query": { 
     "match": { 
      "posts.caption": "adidas" 
     } 
     }, 
     "inner_hits": {} 
    } 
    } 
} 

然而,在我的結果,即使第二文檔具有內點擊率較高的最高分,第一個文檔的根分數在某種程度上更高。

{ 
    "hits": { 
    "total": 2, 
    "max_score": 4.3327584, 
    "hits": [ 
     { 
     "_index": "channels", 
     "_type": "channel", 
     "_id": "1", 
     "_score": 4.3327584, 
     "_source": { 
      "username": "user1", 
      "posts": [...] 
     }, 
     "inner_hits": { 
      "posts": { 
      "hits": { 
       "total": 2, 
       "max_score": 5.5447335, 
       "hits": [...] 
      } 
      } 
     } 
     }, 
     { 
     "_index": "channels", 
     "_type": "channel", 
     "_id": "2", 
     "_score": 4.2954993, 
     "_source": { 
      "username": "user2", 
      "posts": [...] 
     }, 
     "inner_hits": { 
      "posts": { 
      "hits": { 
       "total": 13, 
       "max_score": 11.446381, 
       "hits": [...] 
      } 
      } 
     } 
     } 
    ] 
    } 
} 
+1

我不知道這個問題的答案在我頭頂,但它似乎像解釋參數可能能夠引導你到你的答案。您是否嘗試過在頂級查詢中轉換「explain」:true?這通常會給我類似問題的答案。 – Miek

+0

謝謝,是的,我應該在我問這個問題之前就跑過了,馬上給了我答案。 – zachdb86

+0

是的,這是一個非常有用的選項。很高興它的工作 – Miek

回答

0

上運行我的查詢說明之後,我可以看到TF/IDF分數內命中確實使用來自全國各地的所有根文件嵌套文件計算的IDF。

至於根文件評分,嵌套文件的默認評分模式是平均評分。如果我想使用嵌套文檔的最大分數,我可以通過定義score_mode來設置它。下面的查詢顯示瞭如何在文檔上運行解釋以及設置不同的分數模式。

GET channels/channel/1/_explain 
{ 
    "query": { 
    "nested": { 
     "path": "posts", 
     "score_mode": "max", 
     "query": { 
     "match": { 
      "posts.caption": "adidas" 
     } 
     }, 
     "inner_hits": {} 
    } 
    } 
} 
相關問題