我想要通过几个函数进行复杂的排名,我希望通过搜索_score来加权和乘法。我理解这可以通过function_score - >函数参数。这就是我所拥有的(注意,这是Python):
"function_score": {
"query": ...,
"functions": [
{
"random_score" : {
"seed": seed
},
"weight": 0.1
},
{
"field_value_factor": {
"field": "score"
},
"weight": 1
}
],
"score_mode": "multiply"
}
注意:
观察到的行为:
我做错了什么?还有其他调试方法吗?
编辑:解释输出
刚刚发现了解释命令!以下是得分最高的结果输出。试图绕过它...
"_explanation": {
"value": 0,
"description": "function score, product of:",
"details": [
{
"value": 1,
"description": "ConstantScore(*:*), product of:",
"details": [
{
"value": 1,
"description": "boost"
},
{
"value": 1,
"description": "queryNorm"
}
]
},
{
"value": 0,
"description": "Math.min of",
"details": [
{
"value": 0,
"description": "function score, score mode [multiply]",
"details": [
{
"value": 90500,
"description": "function score, product of:",
"details": [
{
"value": 1,
"description": "match filter: *:*"
},
{
"value": 90500,
"description": "product of:",
"details": [
{
"value": 9.05,
"description": "field value function: (doc['score'].value * factor=10.0)"
},
{
"value": 10000,
"description": "weight"
}
]
}
]
},
{
"value": 0,
"description": "function score, product of:",
"details": [
{
"value": 1,
"description": "match filter: *:*"
},
{
"value": 0,
"description": "product of:",
"details": [
{
"value": 0,
"description": "random score function (seed: 16121)"
},
{
"value": 0.01,
"description": "weight"
}
]
}
]
}
]
},
{
"value": 3.4028235e+38,
"description": "maxBoost"
}
]
},
{
"value": 1,
"description": "queryBoost"
}
]
}
编辑2:
所以看起来随机函数总是返回0,然后乘以其他因子当然总数为0 ......为什么会这样?
答案 0 :(得分:1)
我觉得这是你提供的种子价值的问题。 种子值用于计算随机分数。 相同的种子值始终给出相同的随机数。
因此,如果从查询中删除种子值,它应该可以正常工作。 您可以参考此示例 -
"function_score": {
"query": ...,
"functions": [
{
"random_score" : {
},
"weight": 0.1
},
{
"field_value_factor": {
"field": "score"
},
"weight": 1
}
],
"score_mode": "multiply"
}
如果您想使用种子值,请尝试使用非常大的数字。