【问题标题】:Assign custom scores to clauses in boolean query in Elasticsearch在 Elasticsearch 中为布尔查询中的子句分配自定义分数
【发布时间】:2021-09-12 14:06:58
【问题描述】:

在 Elasticsearch 中,我正在测试以下查询:

GET sdata/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": { "f1": "sth" } }
      ],
      "should": [
        { "match": { "f2": "sth" } }
      ]
    }
  }
}

我知道检索到的文档的总分取决于它们达到的匹配数。但是是否可以自定义最终分数,以便匹配 should 子句的文档的权重可能比单独匹配 must 的文档高得多?我可以添加一个脚本来确定每个子句对最终分数的贡献吗?

提前谢谢你

【问题讨论】:

    标签: elasticsearch scoring booleanquery


    【解决方案1】:

    您可以将boost 参数与should 子句一起使用

    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "f1": "sth"
              }
            }
          ],
          "should": [
            {
              "match": {
                "f2": {
                  "query": "sth",
                  "boost": 10
                }
              }
            }
          ]
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-23
      • 2017-05-22
      • 1970-01-01
      • 1970-01-01
      • 2016-05-11
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多