Elasticsearch衰变函数得分

时间:2017-02-16 09:37:06

标签: elasticsearch

我正在尝试以下

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。我错过了什么?

1 个答案:

答案 0 :(得分: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
    }
  }
}