0
我有我已经简化到这样的查询:Elasticsearch功能评分查询得分
GET /foos-33/_search
{
"from" : 0,
"size" : 25,
"query" : {
"function_score" : {
"query" : {
"bool" : {
"filter" : {
"bool" : {
"must" : [ {
"bool" : {
"must_not" : {
"terms" : {
"foo.id" : [ ]
}
}
}
} ]
}
}
}
},
"functions" : [ {
"field_value_factor" : {
"field" : "foo.strategicBoost",
"missing" : 1.0
}
} ],
"score_mode" : "sum"
}
},
"explain" : true,
"sort" : [ {
"counts.barsPerDay" : {
"order" : "desc"
}
} ]
}
命中的得分始终为零。解释输出排序显示为什么发生这种情况,但我不完全理解这是怎么回事:
"_explanation": {
"value": 0,
"description": "function score, product of:",
"details": [
{
"value": 0,
"description": "ConstantScore(-() +*:*), product of:",
"details": [
{
"value": 0,
"description": "boost",
"details": []
},
{
"value": 1,
"description": "queryNorm",
"details": []
}
]
},
{
"value": 10,
"description": "min of:",
"details": [
{
"value": 10,
"description": "field value function: none(doc['foo.strategicBoost'].value?:1.0 * factor=1.0)",
"details": []
},
{
"value": 3.4028235e+38,
"description": "maxBoost",
"details": []
}
]
}
]
}
},
我试图把它包在constant_score从0常数比分改为1,这样的:
GET /foos-33/_search
{
"from" : 0,
"size" : 25,
"query" : {
"function_score" : {
"query" : {
"bool" : {
"constant_score": {
"boost": 1,
"filter" : {
"bool" : {
"must" : [ {
"bool" : {
"must_not" : {
"terms" : {
"foo.id" : [ ]
}
}
}
} ]
}
}
}
}
},
"functions" : [ {
"field_value_factor" : {
"field" : "foo.strategicBoost",
"missing" : 1.0
}
} ],
"score_mode" : "sum"
}
},
"explain" : true,
"sort" : [ {
"counts.barsPerDay" : {
"order" : "desc"
}
} ]
}
但是这给了我一个错误信息:
"failed_shards": [
{
"shard": 0,
"index": "foos-33",
"node": "A9s2Ui3mQE2SBZhY2VkZGw",
"reason": {
"type": "query_parsing_exception",
"reason": "[bool] query does not support [constant_score]",
"index": "foos-33",
"line": 8,
"col": 29
}
}
]
还有另一种方法我可以尝试解决这个问题 - 我可以尝试到product
更改为sum
或东西 - 但我无法揣摩出product
的来源。