ElasticSearch REST client


(Venkata Sreekanth Bhagavatula) #1

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();
}

		}

(Bertrand Renuart) #2

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


(Venkata Sreekanth Bhagavatula) #3

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


(system) #4

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