Stats feature for Java client with subsequent additions to index

I am having problems getting stats for indices in java. I am using ES 5.4.1
I have 2 indices twitter1 and twitter2.

  • I write an object to twitter1 using the IndexRequest object, and do a refresh on the index
    IndexRequest ir = Requests.indexRequest(index).type(A.TYPE).source(...);

  • I print out the number of objects in the index, and it's size. I use code as
    long count = client.prepareSearch(indexName).setSource(..).get().getHits().getTotalHits();
    For the size, I use
    IndicesStatsRequest req = new IndicesStatsRequest();
    req.all().flush(true);
    IndicesStatsResponse stats = client.admin().indices().prepareStats().clear().setIndices(indexName).setStore(
    true).execute().actionGet();
    ByteSizeValue bytes = stats.getIndex(indexName).getTotal().getStore().getSize();
    size = bytes.getBytes();

Everything is printed fine.

Now, I repeat the process - add a new element to the index, and print out the stats.

The count variable is updated correctly, the size object does not update. If I put a sleep somewhere in between, it gives a correct answer.

I have tried using a listener - a LatchedActionListener, but that does not help either.

I also tried
IndicesStatsRequest req = new IndicesStatsRequest();
req.all();
ActionFuture statsResponseFeature = client.admin().indices().stats(req.clear().flush(true).refresh(true));
IndicesStatsResponse statsResponse = statsResponseFeature.get(1, TimeUnit.MINUTES);
But this did not retrieve any useful information.

Maybe I am missing some flush mechanism?

Some direction would be much appreciated

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