弹性搜索:“function_score"使用“boost_mode":“替换"忽略功能分数 [英] Elasticsearch: "function_score" with "boost_mode":"replace" ignores function score
问题描述
我正在尝试使用 function_score 中定义的不同函数修改来自正常查询的分数.
I am trying to modify scores from normal query with different functions defined in function_score.
为了找出我的函数计算出的分数,我将boost_mode"指定为replace".但是,这会使所有分数保持不变:都等于 1.
To find out what scores calculated by my functions are, I specify "boost_mode" to "replace". However, this makes all scores constant: all equal to 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
}
我希望在这里得到不同的分数,这取决于姓名"字段是包含男人"还是男人".此类文档肯定存在于索引中.
I am expecting to get different scores here, depending on whether "name" field contain "men" or "man". Such documents are present in index for sure.
此外,如果我指定解释":true,我得到的解释中显示的分数与命中的 _score 字段中显示的分数不同:
Moreover, if I am specifying "explain": true, I am getting score shown in explaination different to one shown in _score field of hit:
{
"_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"
}
]
}
}
这里的解释显示value":1.2249949,而_score"为1.
Here explanation shows "value":1.2249949, while "_score" is 1.
我做错了什么?如何获得使用 functinon_score 函数计算的实际分数[在与原始查询分数相结合之前]?
What am I doing wrong? How can I get actual scores calculated using functinon_score functions [before combining with original query scores]?
更新:如果找到匹配的产品,我会得到以下信息.出于某种原因,分数是 1,而应该是 2:
Update: Here's what I get if matching product is found. For some reason, score is 1 while it should be 2:
推荐答案
在您的示例中,该函数与任何文档都不匹配:function score, no filter match,
.此外,来自 文档 使用替换时,会发生以下情况:只使用函数分数,忽略查询分数
.所以,情况是这样的:过滤器不匹配 - 所以没有计算得分 - replace
将使查询分数被忽略并使用过滤器中的分数(这不t 存在,因为它不匹配).
In your sample, the function doesn't match any docs: function score, no filter match,
. Also, from the documentation when replace is being used, the following happens: only function score is used, the query score is ignored
. So, the situation is like this: the filter doesn't match - so no scoring is computed - and replace
will make the query score to be ignored and to use the score from the filter (which doesn't exist as it didn't match).
而当函数不匹配时,函数的默认值为1
.您可以使用 "boost_mode": "sum"
进行检查.我的看法是,这就是您看到 1
分数的原因.
And when the function doesn't match, the default value of the function is 1
. You can check this with "boost_mode": "sum"
. My opinion is that this is the reason why you see a score of 1
.
关于 avg
行为,这对我来说看起来不太好,而且很可能是一个错误.我在这里报告了它:https://github.com/elastic/elasticsearch/issues/13732
Regarding the avg
behavior, this doesn't look ok to me and, most likely, it's a bug. I reported it here: https://github.com/elastic/elasticsearch/issues/13732
这篇关于弹性搜索:“function_score"使用“boost_mode":“替换"忽略功能分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!