我们正在尝试从ElasticSearchDB查询,伪代码如下所示。
public String searchMovieRelease(){
String movieRelease=null;
WebTarget webTarget = target.path("_search/template"); (1)
Invocation.Builder builder = getInvokationBuilder(target); (2)
movieRelease = builder.post(Entity.json(query)); (3)
return movieRelease;
}
- 获取指向所需URI的目标。
- 获取构建
- 通过构建器发布请求查询,并从弹性搜索中获得响应。
现在,我如何使用RestHighLevelClient实现相同的功能。
你可以这样做:
var client = new RestHighLevelClient(RestClient.builder(HttpHost.create("host"))
.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(60000).setSocketTimeout(60000)));
var lowClient = client.getLowLevelClient();
var request = new Request("GET", "endpoint");
var response = lowClient.performRequest(request);