diff --git a/dsRag/ElasticSearch/T4_InsertData.py b/dsRag/ElasticSearch/T3_InsertData.py similarity index 100% rename from dsRag/ElasticSearch/T4_InsertData.py rename to dsRag/ElasticSearch/T3_InsertData.py diff --git a/dsRag/ElasticSearch/T4_SelectAllData.py b/dsRag/ElasticSearch/T4_SelectAllData.py new file mode 100644 index 00000000..2d79df98 --- /dev/null +++ b/dsRag/ElasticSearch/T4_SelectAllData.py @@ -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']) \ No newline at end of file diff --git a/dsRag/ElasticSearch/T5_select_all_data.py b/dsRag/ElasticSearch/T5_SelectByTags.py similarity index 100% rename from dsRag/ElasticSearch/T5_select_all_data.py rename to dsRag/ElasticSearch/T5_SelectByTags.py