'commit'
This commit is contained in:
28
dsLightRag/ElasticSearch/T4_SelectAllData.py
Normal file
28
dsLightRag/ElasticSearch/T4_SelectAllData.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from Config import Config
|
||||
from ElasticSearch.Utils.EsSearchUtil import EsSearchUtil
|
||||
|
||||
# 创建EsSearchUtil实例
|
||||
search_util = EsSearchUtil(Config.ES_CONFIG)
|
||||
|
||||
# 查询所有数据
|
||||
def select_all_data(index_name):
|
||||
try:
|
||||
# 调用EsSearchUtil中的select_all_data方法
|
||||
response = search_util.select_all_data()
|
||||
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'])
|
Reference in New Issue
Block a user