弹性搜索查询术语和评分

mom*_*omo 6 elasticsearch tire

我有一个使用以下条款的请求:

{
"query": {
  "bool": {
    "should": [
      {
        "terms": {
          "subjects.id": [
            1,
            2,
            3
          ], boost: 3
        }
      },
      {
        "terms": {
          "qualification_type.id": [
            3,
            5
          ], boost: 2
        }
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

我的工作得很好,但是对于匹配三个主题的文档而不是仅匹配一个主题的文档的分数更高.

我的问题是:如果主题有一个或多个匹配,有没有办法强制得分相同?

提前致谢 !

imo*_*tov 9

您可以将术语查询转换为过滤器并将其包装到常量分数查询中.例如:

{
    "query": {
        "bool": {
            "should": [{
                "constant_score": {
                    "filter": {
                        "terms": {
                            "subjects.id": [1, 2, 3]
                        }
                    },
                    boost: 3
                }
            }, {
                "constant_score": {
                    "filter": {
                        "terms": {
                            "qualification_type.id": [3, 5]
                        }
                    },
                    boost: 2
                }
            }]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)