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.

33 lines
1003 B

1 month ago
from elasticsearch import Elasticsearch
from Config.Config import ES_CONFIG
from Util.EsMappingUtil import create_vector_index, delete_index # 导入工具函数
# 初始化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"]
)
def manage_index(action, index_name="knowledge_base", dims=200):
"""管理Elasticsearch索引
:param action: 'create''delete'
:param index_name: 索引名称
:param dims: 向量维度(仅创建时有效)
"""
if action == "create":
return create_vector_index(index_name, dims)
elif action == "delete":
return delete_index(index_name)
else:
raise ValueError("action参数必须是'create''delete'")
# 使用示例
if __name__ == "__main__":
# 删除索引
manage_index("delete")
# 创建索引
manage_index("create", dims=200)