# Stats feature for Java client with subsequent additions to index

**URL:** <https://discuss.elastic.co/t/stats-feature-for-java-client-with-subsequent-additions-to-index/90003>\
**Category:** Elasticsearch\
**Created:** [June 19, 2017, 11:29pm UTC](https://discuss.elastic.co/t/stats-feature-for-java-client-with-subsequent-additions-to-index/90003 "2017-06-19T23:29:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elastic\_boston](https://avatars.discourse-cdn.com/v4/letter/e/a183cd/32.png) [@elastic\_boston](https://discuss.elastic.co/u/elastic_boston)\
**Post date:** [June 19, 2017, 11:29pm UTC](https://discuss.elastic.co/t/stats-feature-for-java-client-with-subsequent-additions-to-index/90003/1 "2017-06-19T23:29:59Z")

</div>

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

---

<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:** [July 17, 2017, 11:30pm UTC](https://discuss.elastic.co/t/stats-feature-for-java-client-with-subsequent-additions-to-index/90003/2 "2017-07-17T23:30:18Z")

</div>

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