有没有一种方法可以在查询分数为0时添加function_score,ElasticSearch

csbfibhn  于 2023-01-16  发布在  ElasticSearch
关注(0)|答案(1)|浏览(145)

我有如下查询

{
  "explain": true,
  "query": {
    "bool": {
      "should": {
        "function_score": {
          "functions": [
            {
              "gauss": {},
              "weight": 10
            },
            {
              "filter": {},
              "weight": 5
            }
          ],
          "score_mode": "sum",
          "query": {
            "match": {
              "locality": {
                "query": "whitefield Mall"
              }
            }
          },
          "boost_mode": "sum",
          "boost": "30"
        }
      }
    }
  },
  "size": 1
}

对于查询得分为0的结果,即使它有一些函数得分,它的总得分也会变为0。我如何避免这种情况?
我想要的是将_score作为函数得分和查询得分的总和,即使查询得分为0
已经尝试过玩其他boost_mode,但没有工作

uujelgoq

uujelgoq1#

一种方法是将查询和函数放在不同的function_score中

{
  "explain": true,
  "query": {
    "bool": {
      "should": {
        "function_score": {
          "functions": [
            {
              "gauss": {},
              "weight": 10
            },
            {
              "filter": {},
              "weight": 5
            }
          ],
          "score_mode": "sum",
          "query": {
            "match": {
              "locality": {
                "query": "whitefield Mall"
              }
            }
          },
          "boost_mode": "sum",
          "boost": "30"
        }
      }
    }
  },
  "size": 1
}

相关问题