# How list index and size using python

**URL:** <https://discuss.elastic.co/t/how-list-index-and-size-using-python/350235>\
**Category:** Elasticsearch\
**Created:** [January 2, 2024, 12:17pm UTC](https://discuss.elastic.co/t/how-list-index-and-size-using-python/350235 "2024-01-02T12:17:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pratik\_jain163](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pratik_jain163/32/93354_2.png) [@pratik\_jain163](https://discuss.elastic.co/u/pratik_jain163)\
**Post date:** [January 2, 2024, 12:17pm UTC](https://discuss.elastic.co/t/how-list-index-and-size-using-python/350235/1 "2024-01-02T12:17:06Z")

</div>

i tried to write one Python code for get ES index and size but it gave me a huge json output and I was not able to find an exact result.

how we can do this.

`es.indices.stats(index=index)`

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [January 2, 2024, 1:21pm UTC](https://discuss.elastic.co/t/how-list-index-and-size-using-python/350235/2 "2024-01-02T13:21:14Z")

</div>

Hi @pratik_jain163

Try this:

```auto
    indice = 'indexname'

    params = {"filter_path": "indices.{0}.total.store.size_in_bytes".format(indice)}

    response = get_client().indices.stats(index=indice, metric="store", filter_path=params['filter_path'])

    size_in_bytes = response['indices'][indice]['total']['store']['size_in_bytes']

    print(f"Index Size: '{indice}': {size_in_bytes} bytes")

```

---

<div class="post-metadata">

**Author:** ![pratik\_jain163](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pratik_jain163/32/93354_2.png) [@pratik\_jain163](https://discuss.elastic.co/u/pratik_jain163)\
**Post date:** [January 2, 2024, 2:35pm UTC](https://discuss.elastic.co/t/how-list-index-and-size-using-python/350235/3 "2024-01-02T14:35:19Z")

</div>

thanks @RabBit_BR for response.  
i tried below

```auto
index_stats = es.indices.stats(index=index_name)
        if index_stats and 'indices' in index_stats:
            size_in_bytes = index_stats['indices'][index_name]['total']['store']['size_in_bytes']
            # Convert bytes to a human-readable format
            size_in_gb = size_in_bytes / (1024**3) # Convert bytes to GB
            return size_in_gb
        else:

```

---

<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:** [January 30, 2024, 2:36pm UTC](https://discuss.elastic.co/t/how-list-index-and-size-using-python/350235/4 "2024-01-30T14:36:08Z")

</div>

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