Race condition when removing, indexing and counting data by using the JAVA API?

I'm creating a little wrapper around the elasticsearch java api and found something weird. In my code I have the following sequence of execution:

  1. Remove index

    .admin().indices().delete(DeleteIndexRequest).get();

2.Create index and index some data with bulk request

bulkRequest.add(IndexRequest)
bulkRequest.execute().get();

3.And finally get count of records:

.getClient().prepareCount(indexes);

The problem is that the count always shows 0 records. To make it working I have to add Thread.Sleep between inserting/indexing data and getting count. I thought that get executes when operation is completed. Is it normally behaviour here? Should I wait a little more to give time to indexing data before execute count?

I believe a get operation for a single document by id is always consistent but that counting documents counts as a query and therefore won't be correct until the index has been refreshed.

You were right. Thanks!