我想操作由函数计算的最终分数。

{
    "query": {
        "function_score": {
            "functions": [
                {
                    //Some decay function --> f1
                },
                {
                    //Some decay function --> f2
                },
                {
                    //Some field_value_factor --> f3
                }
            ],
            "score_mode": "sum",
            "boost_mode": "replace"
        }
    }
}

该查询将计算最终分数,如下所示:final score = f1 + f2 + f3
有没有办法像这样最终得分?
final score = (f1 + f2 + f3) * doc['fancy_field']

最佳答案

您可以将function_score查询包装在另一个具有 script_score 函数的查询中,该功能可以将包装查询的_score(即f1 + f2 + f3)乘以doc.fancy_field.value

{
  "query": {
    "function_score": {
      "query": {
          "function_score": {
            "query": {"match_all": {}},
            "functions": [
                {
                    //Some decay function --> f1
                },
                {
                    //Some decay function --> f2
                },
                {
                    //Some field_value_factor --> f3
                }
            ],
            "score_mode": "sum",
            "boost_mode": "replace"
          }
      },
      "functions": [
        {
          "script_score": {
            "script": {
              "inline": "_score * doc['fancy_field'].value"
            }
          }
        }
      ],
      "score_mode": "multiply",
      "boost_mode": "replace"
    }
  }
}

关于elasticsearch - 操作功能计算的最终分数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40590453/

10-15 19:30