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.

35 lines
1.3 KiB

from elasticsearch import Elasticsearch
import ssl
import warnings
from urllib3.exceptions import InsecureRequestWarning
# Suppress only the single InsecureRequestWarning from urllib3
warnings.filterwarnings('ignore', category=InsecureRequestWarning)
warnings.filterwarnings('once', category=DeprecationWarning)
warnings.filterwarnings('once', category=UserWarning)
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
es = Elasticsearch(
hosts="https://10.10.14.206:9200",
basic_auth=("elastic", "jv9h8uwRrRxmDi1dq6u8"),
ssl_context=context,
verify_certs=False,
ssl_show_warn=False # This will suppress the Elasticsearch warning
)
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)}")