2017-10-11 64 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": {} 
    } 
    } 
}