# Java High Rest Client, how to call CLOSE() waiting for ASYNC request

**URL:** <https://discuss.elastic.co/t/java-high-rest-client-how-to-call-close-waiting-for-async-request/114563>\
**Category:** Elasticsearch\
**Created:** [January 8, 2018, 4:43pm UTC](https://discuss.elastic.co/t/java-high-rest-client-how-to-call-close-waiting-for-async-request/114563 "2018-01-08T16:43:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelsogos](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@michaelsogos](https://discuss.elastic.co/u/michaelsogos)\
**Post date:** [January 8, 2018, 4:43pm UTC](https://discuss.elastic.co/t/java-high-rest-client-how-to-call-close-waiting-for-async-request/114563/1 "2018-01-08T16:43:39Z")

</div>

Dear,

How is it possible to wait for ASYNC REQUEST complete before call Close()?

We are using Java High Rest Client.

Our target is to create one instance of RestHighLevelClient, make many ASYNC requests (using indexAsync() method) and close the client.

Actually our issue is that we send many ASYNC request from inside a ForEach and at the end of the ForEach we call the Close() method of the client. Unfortunately it is so fast that no documents will be saved in Elastic index because we call the Close() methods before the requests has been sent to Elastic.

How we should manage this properly?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 8, 2018, 4:55pm UTC](https://discuss.elastic.co/t/java-high-rest-client-how-to-call-close-waiting-for-async-request/114563/2 "2018-01-08T16:55:05Z")

</div>

Why not using the bulk processor instead?

That'd be much more efficient IMO.

---

<div class="post-metadata">

**Author:** ![michaelsogos](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@michaelsogos](https://discuss.elastic.co/u/michaelsogos)\
**Post date:** [January 8, 2018, 5:07pm UTC](https://discuss.elastic.co/t/java-high-rest-client-how-to-call-close-waiting-for-async-request/114563/3 "2018-01-08T17:07:00Z")

</div>

Great Idea!

I will try 🙂

---

<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:** [February 5, 2018, 5:08pm UTC](https://discuss.elastic.co/t/java-high-rest-client-how-to-call-close-waiting-for-async-request/114563/4 "2018-02-05T17:08:01Z")

</div>

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