我想有一个由几个函数组成的复杂排名,我想用搜索_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"
}
笔记:
- 每个文档都有一个"分数"字段,其中包含一个介于 0 和 1 之间的数字
- "种子"是根据用户ID和当前日期生成的
观察到的行为:
- 如果我注释掉field_value_factor函数,结果是随机排名的。
- 如果我注释掉random_score函数,结果按其分数字段排序。
- 如果我不注释掉任何东西,结果与仅随机相同:第二个函数似乎被忽略 了
- 即使将权重更改为剧烈的值也不会对排名产生任何影响
- 此外,在field_value_factor函数中使用"因子"不会执行任何操作
- 交换订单也不会改变行为...
我做错了什么?还有其他方法可以调试吗?
编辑:解释输出
刚刚发现解释命令!下面是得分最高的结果的输出。试图把我的头缠绕在它周围...
"_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...为什么?
我觉得这是您提供的种子值的问题。种子值用于计算随机分数。相同的种子值始终给出相同的随机数。
因此,如果您从查询中删除种子值,它应该可以正常工作。你可以参考这个例子 -
"function_score": {
"query": ...,
"functions": [
{
"random_score" : {
},
"weight": 0.1
},
{
"field_value_factor": {
"field": "score"
},
"weight": 1
}
],
"score_mode": "multiply"
}
如果要使用种子值,请尝试使用非常大的数字。