Elasticsearch: combine function scores

只愿长相守 提交于 2020-01-05 04:00:13

问题


I'm scoring es query with three functions:

{
  "query": {
    "function_score": {
      "query": {
        "bool": {
          ...
        }
      }
    }
  },
  "score_mode": "multiply",
  "boost_mode": "replace",
  "functions": [
    { f1 },
    { f2 },
    { f3 }
  ]
}

so the score would be: f1(doc) * f2(doc) * f3(doc).

But what I want is f1(doc) * f2(doc) + f3(doc), any solutions?


回答1:


This might work, i.e. we multiply the scores of functions f1 and f2 together and then we add that score to the query score which is another function_score query just for f3.

{
  "query": {
    "function_score": {
      "query": {
        "function_score": {
          "query": { "match_all": {}},
          "functions": [
            {
              "f3": {...}
            }
          ]
        }
      },
      "functions": [
        {
          "f1": {...}
        },
        {
          "f2": {...}
        }
      ],
      "score_mode": "multiply",
      "boost_mode": "sum"
    }
  }
}



回答2:


there is a sum option for the score mode

"score_mode": "sum",

this should allow you to sum the scores.

see f.e. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html



来源:https://stackoverflow.com/questions/49110450/elasticsearch-combine-function-scores

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!