我正在尝试使用 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
}
我期望在这里得到不同的分数,具体取决于“name”字段是否包含“men”或“man”。此类文档肯定存在于索引中。
此外,如果我指定 "explain": true,我得到的解释中显示的分数与命中的 _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"
}
]
}
}
这里的解释显示“value”:1.2249949,而“_score”为1。
我究竟做错了什么?如何获得使用 functinon_score 函数计算的实际分数 [在与原始查询分数结合之前]?
Update: Here's what I get if matching product is found. For some reason, score is 1 while it should be 2: