使用 RestHighLevelClient 调用搜索模板 URI
Invoke Search Template URI using RestHighLevelClient
我们正在尝试从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 的目标。
- 获取构建
- Post 通过构建器请求查询并从弹性搜索中获取响应。
现在,我该怎么做,我使用 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);
我们正在尝试从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 的目标。
- 获取构建
- Post 通过构建器请求查询并从弹性搜索中获取响应。
现在,我该怎么做,我使用 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);