From 86a13427800e23492fae954e3ca05761df09e573 Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Mon, 23 Jun 2025 17:00:35 +0800 Subject: [PATCH] 'commit' --- dsRag/T3_LinkEs.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 dsRag/T3_LinkEs.py diff --git a/dsRag/T3_LinkEs.py b/dsRag/T3_LinkEs.py new file mode 100644 index 00000000..f5f7dc28 --- /dev/null +++ b/dsRag/T3_LinkEs.py @@ -0,0 +1,45 @@ +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)}") \ No newline at end of file