How to make synchronous call in ES java API

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)
    assert response.getId() != null;

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

SearchResponse response = txClient.prepareSearch(some_values).setTypes(some_value)

I did not get newly added indexes.

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


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.

Your code does not delete but index.

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