gpt4 book ai didi

ElasticSearch:使用多个加权函数进行排名;使用 random_score 时,其他功能将被忽略

转载 作者:行者123 更新时间:2023-11-29 02:57:07 24 4
gpt4 key购买 nike

我想要一个由多个函数组成的复杂排名,我想对这些函数进行加权并与搜索 _score 相乘。我知道这可以通过 function_score -> functions 参数实现。这是我所拥有的(注意,这是 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"
}

如果你想使用种子值,那么尝试使用一个非常大的数字。

关于ElasticSearch:使用多个加权函数进行排名;使用 random_score 时,其他功能将被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27843674/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com