笔记|ElasticSearch|Python API 获取满足条件的索引

>>> from elasticsearch import Elasticsearch
>>> es_client = Elasticsearch(es_host, timeout=60)

使用如下 API 可以通过 ElasticSearch 的 Python API 获取所有满足 es_index* 的索引信息,返回的结果格式为 List[dict],每一个字典元素为一个索引。

>>> es_client.cat.indices(index="es_index*", format="json")
[{
    
    'health': 'yellow', 'status': 'open', 'index': 'es_index-test', 'uuid': 'DlOWol1ZSSOYNzdtHvVYTg', 'pri': '2', 'rep': '1', 'docs.count': '1', 'docs.deleted': '0', 'store.size': '7.7kb', 'pri.store.size': '7.7kb'}, {
    
    'health': 'yellow', 'status': 'open', 'index': 'es_index-test2', 'uuid': '8alFWRUbRyOpBpkN8QbtyA', 'pri': '2', 'rep': '1', 'docs.count': '8', 'docs.deleted': '0', 'store.size': '1.7mb', 'pri.store.size': '1.7mb'}, ......

以上 API 也可以支持查询多个满足条件的索引:

>>> es_client.cat.indices(index=["es_index-type1-*", "es_index-type2-*"], format="json")
[{
    
    'health': 'yellow', 'status': 'open', 'index': 'es_index-type1-tet', 'uuid': 'DlOWol1ZSSOYNzdtHvVYTg', 'pri': '2', 'rep': '1', 'docs.count': '1', 'docs.deleted': '0', 'store.size': '7.7kb', 'pri.store.size': '7.7kb'}, {
    
    'health': 'yellow', 'status': 'open', 'index': 'es_index-type2-test', 'uuid': '8alFWRUbRyOpBpkN8QbtyA', 'pri': '2', 'rep': '1', 'docs.count': '8', 'docs.deleted': '0', 'store.size': '1.7mb', 'pri.store.size': '1.7mb'}, ......

猜你喜欢

转载自blog.csdn.net/Changxing_J/article/details/129726618
今日推荐