Get Size of only primary shards

How can i get the size of only primary shards?
using java api?

Hi @prasanna_kumar,

very quick and dirty but should get you started:

long totalSizeInBytes = 0;
for (Map.Entry<String, IndexStats> indexStats : client().admin().indices().prepareStats().get().getIndices().entrySet()) {
    totalSizeInBytes += indexStats.getValue().getPrimaries().getStore().getSize().bytes();
System.out.printf("total size is %d bytes.%n", totalSizeInBytes);

Also: you do not specify what you mean by "size". I assumed you meant size in bytes.


Thank you @danielmitterdorfer it helped.
IndicesStatsResponse response = client.admin().indices().prepareStats(indexName).clear()
ByteSizeValue bsv2 = response.getIndex(indexName).getPrimaries().getStore().getSize();