ElasticSearch使用java api进行字段提升

apa*_*tel 2 search elasticsearch

我是ES新手并尝试使用java apis进行搜索.我无法弄清楚如何使用java apis提供特定的提升.以下是示例:我的索引文档如下所示:

_资源": {

"th_id": 1,
"th_name": "test name",
"th_description": "test desc",
"th_image": "test-img",
"th_slug": "Make-Me-Smart",
"th_show_title": "Coast Tech Podcast",
"th_sh_category": "Alternative Health
Run Code Online (Sandbox Code Playgroud)

}

当我搜索关键字时,如果他们在"th_name"中找到的结果与在其他某些字段中找到的结果相比,我想提高结果.目前我使用下面的代码进行搜索:

QueryBuilder qb1 = QueryBuilders.multiMatchQuery(keyword, "th_name", "th_description", "th_show_title", "th_sh_category");
SearchResponse response = client.prepareSearch("talk").setTypes("themes")
        .setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(qb1)
        .setFrom(start).setSize(maxRows)
        .setExplain(true).execute().actionGet();
Run Code Online (Sandbox Code Playgroud)

如果在"th_name"字段中找到关键字与在其他字段中找到关键字,在查询时我可以做什么来提升文档?

Ric*_*cha 11

接受的答案对我没有用.我正在使用的ES版本是6.2.4.

QueryBuilders.multiMatchQuery(keyword)
                            .field("th_name" ,2.0f)
                            .field("th_description")
                            .field("th_show_title")
                            .field("content")
Run Code Online (Sandbox Code Playgroud)

希望它可以帮助别人.


run*_*arM 8

您还应该能够在多匹配查询中直接提升字段:

"multi_match查询通过字段json字段中的^符号支持字段提升.

{
  "multi_match" : {
    "query" : "this is a test",
    "fields" : [ "subject^2", "message" ]
  } 
}
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,主题字段中的匹配比消息字段中的重要性高2倍."

在java-api中,只需使用MultiMatchQueryBuilder:

MultiMatchQueryBuilder builder = 
new MultiMatchQueryBuilder( keyword, "th_name^2", "th_description", "th_show_title", "th_sh_category" );
Run Code Online (Sandbox Code Playgroud)

免责声明:未经测试