How list index and size using python

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)

Hi @pratik_jain163

Try this:

    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")

thanks @RabBit_BR for response.
i tried below

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:
1 Like

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