parent
7387948ab1
commit
0c36381249
@ -0,0 +1,44 @@
|
||||
from elasticsearch import Elasticsearch
|
||||
from Config import Config
|
||||
import urllib3
|
||||
|
||||
# 禁用SSL警告
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
# 初始化Elasticsearch连接
|
||||
es = Elasticsearch(
|
||||
hosts=Config.ES_CONFIG['hosts'],
|
||||
basic_auth=Config.ES_CONFIG['basic_auth'],
|
||||
verify_certs=False
|
||||
)
|
||||
|
||||
# 查询所有数据
|
||||
def select_all_data(index_name):
|
||||
try:
|
||||
# 构建查询条件 - 匹配所有文档
|
||||
query = {
|
||||
"query": {
|
||||
"match_all": {}
|
||||
},
|
||||
"size": 1000 # 限制返回结果数量
|
||||
}
|
||||
|
||||
# 执行查询
|
||||
response = es.search(index=index_name, body=query)
|
||||
hits = response['hits']['hits']
|
||||
|
||||
if not hits:
|
||||
print(f"索引 {index_name} 中没有数据")
|
||||
else:
|
||||
print(f"索引 {index_name} 中共有 {len(hits)} 条数据:")
|
||||
for i, hit in enumerate(hits, 1):
|
||||
print(f"{i}. ID: {hit['_id']}")
|
||||
print(f" 内容: {hit['_source'].get('user_input', '')}")
|
||||
print(f" 标签: {hit['_source'].get('tags', '')}")
|
||||
print(f" 时间戳: {hit['_source'].get('timestamp', '')}")
|
||||
print("-" * 50)
|
||||
except Exception as e:
|
||||
print(f"查询出错: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
select_all_data(Config.ES_CONFIG['index_name'])
|
Loading…
Reference in new issue