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.

38 lines
1.2 KiB

1 month ago
'''
conda activate rag
pip install elasticsearch
'''
1 month ago
from elasticsearch import Elasticsearch
import ssl
import warnings
from urllib3.exceptions import InsecureRequestWarning
warnings.simplefilter("once", InsecureRequestWarning)
warnings.simplefilter("once", DeprecationWarning)
warnings.simplefilter("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
)
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)}")