You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
879 B

from Config.Config import ES_CONFIG
from elasticsearch import Elasticsearch
import warnings
# 初始化ES连接
es = Elasticsearch(
hosts=ES_CONFIG["hosts"],
basic_auth=ES_CONFIG["basic_auth"],
verify_certs=ES_CONFIG["verify_certs"],
ssl_show_warn=ES_CONFIG["ssl_show_warn"]
)
try:
# 获取并格式化索引信息
indices = es.cat.indices(format="json", h="index,health,status,pri,rep,docs.count,store.size")
print(f"\nES服务器共有 {len(indices)} 个index:\n")
print("索引名称\t\t健康状态\t状态\t主分片\t副本\t文档数\t存储大小")
print("-" * 80)
for idx in indices:
print(f"{idx['index']}\t{idx['health']}\t{idx['status']}\t{idx['pri']}\t{idx['rep']}\t{idx['docs.count']}\t{idx['store.size']}")
except Exception as e:
print(f"获取索引时出错: {str(e)}")