Home > database >  Invoke Search Template URI using RestHighLevelClient
Invoke Search Template URI using RestHighLevelClient

Time:04-20

We are trying to query from ElasticSearchDB the pseudo code is as shown below.

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;
}
  1. Fetch the target which points to the required URI.
  2. Fetch the build
  3. Post the request the query through the builder and obtain the response from elastic search.

Now, how do, I achieve the same using RestHighLevelClient.

CodePudding user response:

You can do this way:

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);
  • Related