main
HuangHai 1 month ago
parent 90307fd7dd
commit 7d080a9a9c

@ -10,6 +10,7 @@ es = Elasticsearch(
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")
@ -22,4 +23,5 @@ try:
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)}")
print(f"获取索引时出错: {str(e)}")

@ -0,0 +1,20 @@
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"]
)
# 在T3_LinkEs.py中添加测试
res = es.indices.analyze(
index="knowledge_base",
body={"text": "云南省初中在校生情况", "analyzer": "ik_smart"}
)
print(res)
# 预期输出:['云南省', '初中', '在校生', '情况']

@ -7,13 +7,13 @@ logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('sentence_save.log'),
logging.FileHandler('../sentence_save.log'),
logging.StreamHandler()
]
)
from Config.Config import ES_CONFIG
from T2_Txt2Vec import text_to_embedding
from Test.T2_Txt2Vec import text_to_embedding
# 初始化ES连接
es = Elasticsearch(

@ -65,4 +65,4 @@ def test_queries(file_path):
print("="*50)
if __name__ == "__main__":
test_queries("人口变化趋势对云南教育的影响.txt")
test_queries("../人口变化趋势对云南教育的影响.txt")
Loading…
Cancel
Save