【问题标题】:How does Elasticsearch aggregate or weight scores from two sub queries ("bool query" and "decay function")Elasticsearch 如何聚合或加权来自两个子查询(“布尔查询”和“衰减函数”)的分数
【发布时间】:2021-08-24 04:31:08
【问题描述】:

我有一个复杂的 Elasticsearch 查询,如下例所示。该查询有两个子查询:加权布尔查询和衰减函数。我试图了解 Elasticsearch 如何汇总每个子查询的分数。如果我单独运行第一个子查询(加权布尔查询),我的最高分是 20。如果我单独运行第二个子查询(衰减函数),我的分数是 1。但是,如果我同时运行两个子查询,我的最高分是 15。有人可以解释一下吗?

我的第二个相关问题是如何加权两个子查询的分数?

query = { "function_score": {

    "query": {
      "bool": {
        "should": [
          {'match': {'title': {'query': 'Quantum computing', 'boost': 1}}}, 
          {'match': {'author': {'query': 'Richard Feynman', 'boost': 2}}}
        ]
      },
    },

    "functions": [
      { "exp":  # a built-in exponential decay function 
        { 
          "publication_date": {
            "origin": "2000-01-01",
            "offset": "7d",
            "scale":  "180d",
            "decay": 0.5
          },
        },
     }]

}}

【问题讨论】:

    标签: elasticsearch scoring solr-boost


    【解决方案1】:

    我自己通过阅读elasticsearch document on the usage of function_score.找到了答案function_score有一个参数boost_mode指定了查询分数和函数分数是如何结合的。默认情况下,boost_mode 设置为 multiply

    除了默认的multiply方法外,我们还可以将boost_mode设置为avg,并在上述衰减函数exp中添加一个参数weight,那么综合得分为:( the_bool_query_score + the_decay_function_score * weight ) / ( 1 + weight )

    【讨论】:

      猜你喜欢
      • 2017-05-22
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 2011-09-27
      • 2017-09-18
      • 2021-09-10
      相关资源
      最近更新 更多