繁体   English   中英

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

[英]Elasticsearch (Elasticsearch Curator) Python API. Get dictionary of ES indices and their sizes

我可以通过以下代码在列表中获取所有ES索引:

from elasticsearch import Elasticsearch
es = Elasticsearch()

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

但是有可能获得像{'index1': '100gb', 'index2': '10gb', 'index3': '15gb'} 所以我指的是带有索引名称和大小的dic。

策展人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}

我的变体:

import elasticsearch

client = elasticsearch.Elasticsearch()
all_indices = client.indices.stats(metric='store', human=True)['indices'].keys()
dic_indices = {}

for index in all_indices:
    size = client.indices.stats(metric='store', human=True)['indices'][index]['total']['store']['size']
    dic_indices[index] = size

print dic_indices

结果具有下一个视图:

{u'haproxy-2016.09.02': u'1.6gb', u'haproxy-2016.09.03': u'827.3mb', u'marathon-2016.09.03': u'296.1mb', u'docker-2016-09-06': u'187.2mb', u'haproxy-2016.09.06': u'339.7mb', u'haproxy-2016.09.04': u'647.5mb', u'haproxy-2016.09.05': u'595.5mb'}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM