3

我想要一个复杂的排名,它由我想要加权并与搜索_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 函数,结果将按其 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... 为什么会这样?

4

1 回答 1

1

我觉得这是您提供的种子价值的问题。种子值用于计算随机分数。相同的种子值总是给出相同的随机数。

因此,如果您从查询中删除种子值,它应该可以正常工作。您可以参考此示例 -

"function_score": {
    "query": ...,
    "functions": [
        {
            "random_score" : {
            },
            "weight": 0.1
        },
        {
            "field_value_factor": {
                "field":    "score"
            },
            "weight": 1
        }
    ],
    "score_mode": "multiply"
}

如果要使用种子值,请尝试使用非常大的数字。

于 2015-01-10T15:45:07.777 回答