我正在编写一个查询插件,它将构建给定关键字的查询并将其传递给弹性搜索客户端进行处理.
我的处理程序类扩展了BaseRestHandler,我将Client对象注入到我的处理程序的构造函数中.
@Inject
protected QueryHandler(Settings settings, Client client, RestController controller) {
super(settings, client);
controller.registerHandler(GET, "/_query/{queryBuilder}", this);
}
Run Code Online (Sandbox Code Playgroud)
我想知道在handleRequest()方法中使用相同的客户端对象是否是线程安全的?
我是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"字段中找到关键字与在其他字段中找到关键字,在查询时我可以做什么来提升文档?