How to make elasticsearch synchronous call in ActionListner response

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

}

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