gpt4 book ai didi

elasticsearch - Elasticsearch:带 “function_score”的 “boost_mode”忽略:“replace”函数得分

转载 作者:行者123 更新时间:2023-12-03 00:42:23 29 4
gpt4 key购买 nike

我正在尝试使用function_score中定义的不同功能修改普通查询的分数。

为了找出由我的函数计算出的分数,我将“boost_mode”指定为“replace”。但是,这会使所有分数保持不变:全部等于1。

考虑以下查询:

{
"query": {
"function_score": {
"query": {
"terms": {
"name": ["men", "women"]
}
},
"score_mode": "avg",
"functions": [
{
"filter": {
"terms": {
"name": ["men","man"]
}
},
"weight": 2
}
],
"boost_mode": "replace"
}
},
"explain": true,
"from": 0
}

我希望在这里获得不同的分数,具体取决于“姓名”字段包含“男人”还是“男人”。此类文件肯定存在于索引中。

此外,如果我指定“explain”:true,则说明中显示的分数与hit的_score字段中显示的分数不同:
{  
"_shard":0,
"_node":"ro26nlDuTfiTaIlIgHqg4g",
"_index":"products10",
"_type":"product_basic",
"_id":"0c25fc90433481aac0cce62dd1a21e06",
"_score":1,
"_source":{
"category":[
"Chicago Blues",
"Blues",
"Styles",
"Digital Music"
],
"site_name":"www.amazon.com",
"name":"Who's That Women?",
"url":"http://www.amazon.com/dp/B001125F8I/",
"price":0.99,
"reviews":[

],
"breadcrumb":"Digital Music",
"in_stock":true,
"features":[

],
"pic_urls":[
"http://ecx.images-amazon.com/images/I/51CvgPMwtsL.jpg",
"http://ecx.images-amazon.com/images/I/51CvgPMwtsL.jpg"
],
"name_semantic_core":[
"Women ?",
"?"
],
"category_path":"/Chicago Blues/Blues/Styles/",
"visit_datetime":"2014-11-04T11:50:34.169779",
"detected_category":"Digital Music"
},
"_explanation":{
"value":1.2249949,
"description":"function score, no filter match, product of:",
"details":[
{
"value":1.2249949,
"description":"product of:",
"details":[
{
"value":2.4499898,
"description":"sum of:",
"details":[
{
"value":2.4499898,
"description":"weight(name:women in 6181332) [PerFieldSimilarity], result of:",
"details":[
{
"value":2.4499898,
"description":"score(doc=6181332,freq=1.0), product of:",
"details":[
{
"value":0.67790973,
"description":"queryWeight, product of:",
"details":[
{
"value":7.228071,
"description":"idf(docFreq=238699, maxDocs=120967660)"
},
{
"value":0.09378847,
"description":"queryNorm"
}
]
},
{
"value":3.6140356,
"description":"fieldWeight in 6181332, product of:",
"details":[
{
"value":1,
"description":"tf(freq=1.0), with freq of:",
"details":[
{
"value":1,
"description":"termFreq=1.0"
}
]
},
{
"value":7.228071,
"description":"idf(docFreq=238699, maxDocs=120967660)"
},
{
"value":0.5,
"description":"fieldNorm(doc=6181332)"
}
]
}
]
}
]
}
]
},
{
"value":0.5,
"description":"coord(1/2)"
}
]
},
{
"value":1,
"description":"queryBoost"
}
]
}
}

此处的说明显示“值”:1.2249949,而“_score”为1。

我究竟做错了什么?在结合原始查询分数之前,如何获得使用functinon_score函数计算的实际分数?

更新:如果找到匹配的产品,这就是我得到的。出于某种原因,得分为1,而得分应为2:
explanation for a matching product

最佳答案

在您的示例中,该函数与任何文档都不匹配:function score, no filter match,。另外,在使用replace时,从documentation发生以下情况:only function score is used, the query score is ignored。因此,情况如下:过滤器不匹配-因此不计算任何得分-replace将使查询分数被忽略并使用过滤器中的分数(由于不存在而不存在比赛)。

当功能不匹配时,该功能的默认值为1。您可以使用"boost_mode": "sum"进行检查。我的意见是,这就是您看到1分数的原因。

关于avg行为,这在我看来并不好,而且很可能是一个错误。我在这里报告了:https://github.com/elastic/elasticsearch/issues/13732

关于elasticsearch - Elasticsearch:带 “function_score”的 “boost_mode”忽略:“replace”函数得分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32732166/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com