gpt4 book ai didi

python - Elasticsearch (Elasticsearch Curator) Python API。获取 ES 索引及其大小的字典

转载 作者:太空宇宙 更新时间:2023-11-04 08:47:05 27 4
gpt4 key购买 nike

我可以通过这样的代码获取列表中的所有ES索引:

from elasticsearch import Elasticsearch
es = Elasticsearch()

indices=es.indices.get_aliases().keys()
sorted(indices)

但是有没有可能得到像 {'index1': '100gb', 'index2': '10gb', 'index3': '15gb'} 这样的字典。所以我的意思是带有索引名称和大小的 dic。

最佳答案

Curator 4 在 IndexList 初始化时提取大部分索引元数据。如果重要的话,它以字节为单位,而不是以人类可读的大小。

它在IndexList.index_info[index_name]['size_in_bytes']

http://curator.readthedocs.io/en/latest/objectclasses.html#indexlist 阅读有关 IndexList 方法的更多信息

import elasticsearch
import curator
client = elasticsearch.Elasticsearch(host='127.0.0.1')

il = curator.IndexList(client)
print('{0}'.format(il.indices))
[u'topbeat-2016.09.01', ...]

print('{0}'.format(il.index_info['topbeat-2016.09.01'])
{'number_of_replicas': u'1', 'size_in_bytes': 706503044, 'number_of_shards': u'5', 'docs': 1629986, 'age': {'creation_date': 1472688002}, 'state': u'open', 'segments': 0}

关于python - Elasticsearch (Elasticsearch Curator) Python API。获取 ES 索引及其大小的字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39348851/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com