【问题标题】:Elasticsearch (Elasticsearch Curator) Python API. Get dictionary of ES indices and their sizesElasticsearch (Elasticsearch Curator) Python API。获取 ES 索引及其大小的字典
【发布时间】:2017-01-13 21:39:08
【问题描述】:

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

from elasticsearch import Elasticsearch
es = Elasticsearch()

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

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

【问题讨论】:

  • 您使用的是哪个版本的 API? Curator 4 将其作为 IndexList 初始化的一部分。
  • 我问的原因是,您似乎根本没有在这里使用 Curator,即使您在标题和标签中列出了 Elasticsearch Curator。下面的答案是合适的,但仍然没有使用 Curator。策展人标签有误吗?
  • @untergeek 然后我准备使用 curstor-python 绑定作为选项。但看起来它无法显示索引大小信息。
  • 您可能使用的是旧版本。如前所述,策展人 4 具有此功能。下面我再提供一点。

标签: python api dictionary elasticsearch elasticsearch-curator


【解决方案1】:

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}

【讨论】:

    【解决方案2】:

    我的变种:

    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'}
    

    【讨论】:

      猜你喜欢
      • 2017-03-03
      • 2018-07-05
      • 2015-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多