使用术语过滤器和function_score查询总是得分0

时间:2018-03-01 14:04:37

标签: elasticsearch

我需要执行以下操作的查询:

  • 过滤文件
  • 按地理距离分数
  • 使用升压模式“乘法”(这是默认值)

我简化了我的真实查询以进行演示:

"query": {
    "function_score": {
      "query": {
        "bool": {
          "must": [],
          "filter": {
            "bool": {
              "must": [
                {
                  "term": {
                    "is_good": true
                  }
                }
                // here could be another filter
              ]
            }
          }
        }
      },
      "functions": [
        {
          "linear": {
            "locations.geo_point": {
              "origin": {
                "lat": 52.518611,
                "lon": 13.408333
              },
              "offset": "3km",
              "scale": "15km"
            }
          }
        }
      ]
    }
  }

问题:每个文档的得分为0.

弹性搜索

解释

"_explanation": {
          "value": 0,
          "description": "function score, product of:",
          "details": [
            {
              "value": 0,
              "description": "ConstantScore(is_good:T)^0.0",
              "details": []
            },
            {
              "value": 1,
              "description": "min of:",
              "details": [
                {
                  "value": 1,
                  "description": "Function for field locations.geo_point:",
                  "details": [
                    {
                      "value": 1,
                      "description": "max(0.0, ((30000.0 - MIN of: [0.0])/30000.0)",
                      "details": []
                    }
                  ]
                },
                {
                  "value": 3.4028235e+38,
                  "description": "maxBoost",
                  "details": []
                }
              ]
            }
          ]
        }

你看,术语过滤器得分为0.随着乘法,总得分变为0.我一直试图给术语过滤器得分为1或者以某种方式摆脱对得分的影响,但是找不到有效的解决方案。所以我猜,查询必须重新调整,但是如何?

1 个答案:

答案 0 :(得分:1)

我可能参加聚会很晚,但是如果有帮助的话:

如果您想添加实际上会影响得分的must / should子句,则任何一种解决方案都可能会出现问题。然后,您可能想要从代码(或search template)中包含/排除match_all或constant_score。