问题描述
在 Elasticsearch 中,我正在测试以下查询:
GET sdata/_search
{
"query": {
"bool": {
"must": [
{ "match": { "f1": "sth" } }
],"should": [
{ "match": { "f2": "sth" } }
]
}
}
}
我知道检索到的文档的总分取决于它们实现的匹配数。但是是否可以自定义最终分数,以便匹配 should
子句的文档的权重可能比单独匹配 must
的文档高得多?我可以添加一个脚本来确定每个子句对最终分数的影响吗?
提前致谢
解决方法
您可以将 boost
参数与 should
子句一起使用
{
"query": {
"bool": {
"must": [
{
"match": {
"f1": "sth"
}
}
],"should": [
{
"match": {
"f2": {
"query": "sth","boost": 10
}
}
}
]
}
}
}