This commit is contained in:
hailin 2024-10-29 18:12:55 +08:00
parent f864b82255
commit 4d567d98f4
1 changed files with 14 additions and 2 deletions

16
app.py
View File

@ -49,7 +49,7 @@ def store_to_es(key, data: Dict[str, Any], index: str) -> bool:
logging.info(f".............保存到ES出错...............{e}..")
#print(e)
return False
def search_es(key: str, index: str) -> Optional[Dict]:
# 使用term查询来根据文档的_id搜索
@ -81,6 +81,14 @@ def load_indices_from_es(key: str, index: str, buf: Dict[str, Any]) -> Any:
return None
def reload_buf(ikey, ibuf):
ret = load_indices_from_es(ikey, 'customer', ibuf)
if not ret:
exit("客服AI员工不能拥有数据库。")
customer_data=buf[key]['customer database']
app.set_customer_data(customer_data)
def extract_index_structure(es_client, index_name):
"""
扫描 Elasticsearch 索引中的一个文档递归提取字段结构包括嵌套字段生成包含所有字段的层级关系和类型信息
@ -209,6 +217,8 @@ def calculate_statistics():
@app.route('/customer/<int:index>')
def view_customer(index):
reload_buf(key, buf)
# 判断是否有数据
if not customer_data:
return "No customer data provided.", 400
@ -309,6 +319,7 @@ def search_by_email():
if not email:
return "Email address is required.", 400
reload_buf(key, buf)
# 遍历 customer_data 查找匹配的邮件地址
for index, customer in enumerate(customer_data):
for domain, info in customer.items():
@ -328,7 +339,8 @@ def search_by_domain():
domain = request.args.get('domain')
if not domain:
return "Domain is required.", 400
reload_buf(key, buf)
# 遍历 customer_data 查找匹配的域名
for index, customer in enumerate(customer_data):
if domain in customer: