# How to make elasticsearch synchronous call in ActionListner response

**URL:** <https://discuss.elastic.co/t/how-to-make-elasticsearch-synchronous-call-in-actionlistner-response/208945>\
**Category:** Elasticsearch\
**Created:** [November 21, 2019, 5:23pm UTC](https://discuss.elastic.co/t/how-to-make-elasticsearch-synchronous-call-in-actionlistner-response/208945 "2019-11-21T17:23:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![developer\_apk](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@developer\_apk](https://discuss.elastic.co/u/developer_apk)\
**Post date:** [November 21, 2019, 5:23pm UTC](https://discuss.elastic.co/t/how-to-make-elasticsearch-synchronous-call-in-actionlistner-response/208945/1 "2019-11-21T17:23:37Z")

</div>

I am using Elasticsearch java high level rest client and synchronous API calls are hanging forever in onResponse method

```
public String indexDocument(String document) throws Exception {
IndexRequest indexRequest = new IndexRequest("myindex")
        .source(document, XContentType.JSON);
ActionListener<IndexResponse> listener;
listener = new ActionListener<IndexResponse>() {
    @Override
    public void onResponse(IndexResponse indexResponse) {
         try {
              // This call is hanging forever
              RefreshResponse refreshResponse = client.indices().refresh(new RefreshRequest("myindex"), RequestOptions.DEFAULT);
              System.out.println(refreshResponse.getSuccessfulShards());
         }
         catch(Exception e) {

         }
    }

    @Override
    public void onFailure(Exception e) {
        e.printStackTrace();
    }
};
client.indexAsync(indexRequest, RequestOptions.DEFAULT, listener);

```

}

---

<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:** [December 19, 2019, 5:23pm UTC](https://discuss.elastic.co/t/how-to-make-elasticsearch-synchronous-call-in-actionlistner-response/208945/2 "2019-12-19T17:23:43Z")

</div>

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