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>() {
    public void onResponse(IndexResponse indexResponse) {
         try {
              // This call is hanging forever
              RefreshResponse refreshResponse = client.indices().refresh(new RefreshRequest("myindex"), RequestOptions.DEFAULT);
         catch(Exception e) {


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


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