【问题标题】:Elasticsearch decay function scoreElasticsearch 衰减函数得分
【发布时间】:2017-02-16 19:45:21
【问题描述】:

我正在尝试以下方法

PUT test/foo/1
{
  "num": 100
}

GET test/foo/_search
{
  "query" : {
    "function_score" : {
      "query" : {
        "match" : {
          "num": 100
        }
      },
      "functions" : [
        {
          "filter" : {
            "match_all" : {
            }
          },
          "gauss" : {
            "num" : {
              "origin": 0,
              "scale" : 500,
              "offset" : 0,
              "decay" : 0.1
            },
            "multi_value_mode" : "MIN"
          }
        }
      ],
      "score_mode" : "sum",
      "max_boost" : 3.4028235E38
    }
  }
}

---

{  
  "hits": {
    "total": 1,
    "max_score": 0.91201085,
    "hits": [
      {
        "_index": "test",
        "_type": "foo",
        "_id": "1",
        "_score": 0.91201085,
        "_source": {
          "num": 100
        }
      }
    ]
  }
}

我使用 sum 作为得分模式。由于查询的分数是 1,衰减函数的分数是 0.91201085,我期待分数是 1.91201085。我错过了什么?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    使用 "boot_mode" : "sum" 。您也可以在查询中使用explain 来了解文档的评分方式

    POST testindexy/_search
    {
      "query" : {
        "function_score" : {
          "query" : {
            "match" : {
              "num": 100
            }
          },
          "functions" : [
            {
              "filter" : {
                "match_all" : {
                }
              },
              "gauss" : {
                "num" : {
                  "origin": 0,
                  "scale" : 500,
                  "offset" : 0,
                  "decay" : 0.1
                },
                "multi_value_mode" : "MIN"
              }
            }
          ],
          "boost_mode": "sum", 
          "score_mode" : "sum",
          "max_boost" : 3.4028235E38
        }
      }
    }
    

    【讨论】:

    • 没错,boost_mode 用于将查询分数与 function_score 分数相结合,而score_mode 用于将functions 内部的不同分数相结合。
    猜你喜欢
    • 1970-01-01
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 2015-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多