# How to get the size of an index through java api

**URL:** https://discuss.elastic.co/t/how-to-get-the-size-of-an-index-through-java-api/7892
**Category:** Elasticsearch
**Created:** [May 29, 2012, 1:03pm UTC](https://discuss.elastic.co/t/how-to-get-the-size-of-an-index-through-java-api/7892 "2012-05-29T13:03:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ravikumar\_kotta](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@ravikumar\_kotta](https://discuss.elastic.co/u/ravikumar_kotta)
#### Post date: [May 29, 2012, 1:03pm UTC](https://discuss.elastic.co/t/how-to-get-the-size-of-an-index-through-java-api/7892/1 "2012-05-29T13:03:59Z")

</div>

Hi,

```
     How to get the size of an index through java api. I searched on 

```

web i did n't get any solution for me. please resolve my problem,

thanks  
Ravikumar Kotta

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [May 29, 2012, 4:50pm UTC](https://discuss.elastic.co/t/how-to-get-the-size-of-an-index-through-java-api/7892/2 "2012-05-29T16:50:03Z")

</div>

First you need to get IndicesStats

IndicesStats stats = client.admin().indices().prepareStats()  
.clear()  
.setIndices("twitter")  
.setStore(true)  
.execute().actionGet();

And then use it to get total index size:

long bytes = stats.index("twitter").getTotal().getStore().getSize().bytes();

On Tuesday, May 29, 2012 9:03:59 AM UTC-4, ravi kumar wrote:

> Hi,
> 
> ```
> How to get the size of an index through java api. I searched on 
> 
> ```
> 
> web i did n't get any solution for me. please resolve my problem,
> 
> thanks  
> Ravikumar Kotta

---

<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 6, 2017, 3:26am UTC](https://discuss.elastic.co/t/how-to-get-the-size-of-an-index-through-java-api/7892/3 "2017-07-06T03:26:37Z")

</div>


