ElasticSearch REST client

Can we keep the rest client alive through out the application life cycle. or do we need to close the client after each request.

final RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200, "http")).build();

public void onSuccess(Response response) {
try {
System.out.println(EntityUtils.toString(response.getEntity()));
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
restClient.close(); -- Does this need to happen
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

		}

You can reuse the same RestClient instance through the entire lifetime of your application.

Thank you. That is what the documentation says just wanted to hear from someone else too.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.