如何使用MultiMatchQueryBuilder为每个字段设置提升?

时间:2017-10-13 15:32:50

标签: elasticsearch elasticsearch-5 elasticsearch-java-api

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
   }
}

从查询中为每个字段设置提升的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

试试这个:

final MultiMatchQueryBuilder query
        = new MultiMatchQueryBuilder(keyword).field("number",5).field("description",2);