# How to make synchronous call in ES java API

**URL:** <https://discuss.elastic.co/t/how-to-make-synchronous-call-in-es-java-api/52715>\
**Category:** Elasticsearch\
**Created:** [June 14, 2016, 9:54am UTC](https://discuss.elastic.co/t/how-to-make-synchronous-call-in-es-java-api/52715 "2016-06-14T09:54:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![devender-yadav](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@devender-yadav](https://discuss.elastic.co/u/devender-yadav)\
**Post date:** [June 14, 2016, 9:54am UTC](https://discuss.elastic.co/t/how-to-make-synchronous-call-in-es-java-api/52715/1 "2016-06-14T09:54:18Z")

</div>

I am using Elasticsearch 2.3 _(both server and client)_.

I added some indexes using below mention code:

```
    private TransportClient txClient;
    // client connection code
    IndexResponse response = txClient.prepareIndex(some_values).setSource(some_value)
                              .execute().actionGet();
    assert response.getId() != null;

```

**Immediately after addition** , I searched for that index using `SearchRequestBuilder`.

```
SearchResponse response = txClient.prepareSearch(some_values).setTypes(some_value)
                          .execute().actionGet();

```

I did not get newly added indexes.

All I want to wait until all the indexes are added. How can I achieve that?

## EDIT :

After adding `.setRefresh(true)` to the `prepareIndex()` method, my problem is solved. But as far as I understand, it's not good for performance.

I did not want to refresh it immediately, I want to wait till all the indexes are created in the normal way.

---

<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:** [June 14, 2016, 1:58pm UTC](https://discuss.elastic.co/t/how-to-make-synchronous-call-in-es-java-api/52715/2 "2016-06-14T13:58:38Z")

</div>

Your code does not delete but index.

---

<div class="post-metadata">

**Author:** ![devender-yadav](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@devender-yadav](https://discuss.elastic.co/u/devender-yadav)\
**Post date:** [June 14, 2016, 2:26pm UTC](https://discuss.elastic.co/t/how-to-make-synchronous-call-in-es-java-api/52715/3 "2016-06-14T14:26:46Z")

</div>

I am sorry for the incomplete and confusing question. I updated it

---

<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:** [July 5, 2017, 10:43pm UTC](https://discuss.elastic.co/t/how-to-make-synchronous-call-in-es-java-api/52715/4 "2017-07-05T22:43:53Z")

</div>


