# ElasticSearch REST client

**URL:** <https://discuss.elastic.co/t/elasticsearch-rest-client/85815>\
**Category:** Elasticsearch\
**Created:** [May 15, 2017, 8:18pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client/85815 "2017-05-15T20:18:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkata\_sreekanth\_bh](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@venkata\_sreekanth\_bh](https://discuss.elastic.co/u/venkata_sreekanth_bh)\
**Post date:** [May 15, 2017, 8:18pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client/85815/1 "2017-05-15T20:18:14Z")

</div>

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

```
		}
```

---

<div class="post-metadata">

**Author:** ![Bertrand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bertrand/32/45679_2.png) [@Bertrand](https://discuss.elastic.co/u/Bertrand)\
**Post date:** [May 16, 2017, 3:19pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client/85815/2 "2017-05-16T15:19:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![venkata\_sreekanth\_bh](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@venkata\_sreekanth\_bh](https://discuss.elastic.co/u/venkata_sreekanth_bh)\
**Post date:** [May 16, 2017, 4:12pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client/85815/3 "2017-05-16T16:12:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 13, 2017, 4:12pm UTC](https://discuss.elastic.co/t/elasticsearch-rest-client/85815/4 "2017-06-13T16:12:36Z")

</div>

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