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.

49 lines
1.5 KiB

'''
conda activate rag
pip install elasticsearch
'''
from elasticsearch import Elasticsearch
import ssl
import warnings
from urllib3.exceptions import InsecureRequestWarning
warnings.simplefilter("once", InsecureRequestWarning)
warnings.simplefilter("once", DeprecationWarning)
# 生产环境推荐配置
# 1. 获取服务器CA证书
# 2. 使用以下配置替换当前配置
# context = ssl.create_default_context(cafile="path/to/ca.crt")
# es = Elasticsearch(
# hosts="https://10.10.14.206:9200",
# basic_auth=("elastic", "jv9h8uwRrRxmDi1dq6u8"),
# ssl_context=context
# )
# 开发环境临时方案(带警告抑制)
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)}")