parent
062b5930cf
commit
e40718658b
Binary file not shown.
@ -0,0 +1,49 @@
|
|||||||
|
from elasticsearch import Elasticsearch
|
||||||
|
import warnings
|
||||||
|
from Config import Config
|
||||||
|
from Config.Config import ES_CONFIG
|
||||||
|
|
||||||
|
# 1. 初始化Elasticsearch连接
|
||||||
|
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
||||||
|
es = Elasticsearch(
|
||||||
|
hosts=Config.ES_CONFIG['hosts'],
|
||||||
|
basic_auth=Config.ES_CONFIG['basic_auth'],
|
||||||
|
verify_certs=False
|
||||||
|
)
|
||||||
|
|
||||||
|
# 2. 直接在代码中指定要查询的标签
|
||||||
|
query_tag = "MATH_DATA_1" # 可以修改为其他需要的标签
|
||||||
|
|
||||||
|
# 3. 构建查询条件
|
||||||
|
query = {
|
||||||
|
"query": {
|
||||||
|
"bool": {
|
||||||
|
"must": [
|
||||||
|
{
|
||||||
|
"term": {
|
||||||
|
"tags": query_tag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"size": 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
# 4. 执行查询
|
||||||
|
try:
|
||||||
|
results = es.search(index=ES_CONFIG['index_name'], body=query)
|
||||||
|
print(f"查询标签 '{query_tag}' 结果:")
|
||||||
|
if results['hits']['hits']:
|
||||||
|
for hit in results['hits']['hits']:
|
||||||
|
doc = hit['_source']
|
||||||
|
print(f"ID: {hit['_id']}")
|
||||||
|
print(f"标签: {doc['tags']['tags']}")
|
||||||
|
print(f"用户问题: {doc['user_input']}")
|
||||||
|
print(f"时间: {doc['timestamp']}")
|
||||||
|
print(f"向量: {doc['embedding'][:5]}...")
|
||||||
|
print("-" * 40)
|
||||||
|
else:
|
||||||
|
print(f"未找到标签为 '{query_tag}' 的数据。")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"查询失败: {e}")
|
Loading…
Reference in new issue