如何使用 MultiMatchQueryBuilder 为每个字段设置提升?
How to set the boost for each field using MultiMatchQueryBuilder?
multi_match 查询通过 json 字段中的 ^ 符号支持字段提升,如下所示
{
"multi_match" : {
"query" : "this is the best",
"fields" : [ "number^5", "description^2" ]
}
}
我想使用 java api 实现相同的效果,因此我使用 MultiMatchQueryBuilder
构造如下查询:
final MultiMatchQueryBuilder query
= new MultiMatchQueryBuilder(keyword, "number^5", "description^2");
但是弹性搜索 api 正在按如下方式转换此查询:
{
"multi_match" : {
"query" : "this is the test",
"fields" : [
"number^5.0^1.0",
"description^2.0^1.0"
],
"type" : "best_fields",
"operator" : "OR",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"lenient" : false,
"zero_terms_query" : "NONE",
"boost" : 1.0
}
}
为查询中的每个字段设置提升的正确方法应该是什么?
试试这个:
final MultiMatchQueryBuilder query
= new MultiMatchQueryBuilder(keyword).field("number",5).field("description",2);
multi_match 查询通过 json 字段中的 ^ 符号支持字段提升,如下所示
{
"multi_match" : {
"query" : "this is the best",
"fields" : [ "number^5", "description^2" ]
}
}
我想使用 java api 实现相同的效果,因此我使用 MultiMatchQueryBuilder
构造如下查询:
final MultiMatchQueryBuilder query
= new MultiMatchQueryBuilder(keyword, "number^5", "description^2");
但是弹性搜索 api 正在按如下方式转换此查询:
{
"multi_match" : {
"query" : "this is the test",
"fields" : [
"number^5.0^1.0",
"description^2.0^1.0"
],
"type" : "best_fields",
"operator" : "OR",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"lenient" : false,
"zero_terms_query" : "NONE",
"boost" : 1.0
}
}
为查询中的每个字段设置提升的正确方法应该是什么?
试试这个:
final MultiMatchQueryBuilder query
= new MultiMatchQueryBuilder(keyword).field("number",5).field("description",2);