#!/usr/bin/env python # -*- coding:utf-8 -*- # author : liumiaomiao #从es库中导出数据到测试环境mongo库 from lib.es_tools import esutil from pymongo import MongoClient def ES_bidding(es_query): """ 操作样例:直接拉取数据 """ db_config = { # es 'es_host': '127.0.0.1', 'es_port': 19800, 'es_http_auth': ('jianyuGr','we3g8glKfe#'), # 重新申请 'timeout': 10000, # 'index': "projectset", 'index': "bidding", 'size': 1000, # mongo存的数据库表 'mg_host': '172.20.45.129', 'mg_port': 27002, 'database': 'data_quality', 'collection': 'bidding_20250515_fujian' } query = es_query # 传入查询语句query 以及配置信息 esutil.es_query_save(query, **db_config) def run(): # 根据ES语句查找bidding es_query = {"track_total_hits": True, "query": { "bool": { "must": [{ "range": { "publishtime": { "gte": 1747238400, "lte": 1747324800 } } }, { "bool": { "must": [{ "multi_match": { "query": "详见附件", "type": "phrase", "fields": ["detail"] } }] } }], "must_not": [] } }, "highlight": { "pre_tags": [""], "post_tags": [""], "fields": { "detail": { "fragment_size": 115, "number_of_fragments": 1 } } }, "sort": [{ "dataweight": "desc" }, { "publishtime": "desc" }], "from": 0 } # es_query = {"track_total_hits": True, # "query": {"bool": {"must": [{"range": {"comeintime": {"from": "1747324800", "to": "1747411200"}}}]}}} # es_query = {"track_total_hits": True, # "query": {"bool": {"must": [{"range": {"publishtime": {"from": "1691337600", "to": "1691424000"}}}, # {"terms": {"subtype": ["中标", "合同","成交"]}}]}}} ES_bidding(es_query) run()