es.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # author : liumiaomiao
  4. #从es库中导出数据到测试环境mongo库
  5. from util.es_tools import esutil
  6. from pymongo import MongoClient
  7. def ES_bidding(es_query):
  8. """
  9. 操作样例:直接拉取数据
  10. """
  11. db_config = {
  12. # es
  13. 'es_host': '127.0.0.1',
  14. 'es_port': 9800,
  15. 'es_http_auth': ('test_dataQuality','t9s3Ed0gBBowf5'), # 重新申请
  16. 'timeout': 10000,
  17. # 'index': "projectset",
  18. 'index': "bidding",
  19. 'size': 1000,
  20. # mongo存的数据库表
  21. 'mg_host': '192.168.3.206',
  22. 'mg_port': 27080,
  23. 'database': 'data_quality',
  24. 'collection': 'bidding_20231221'
  25. }
  26. query = es_query
  27. # 传入查询语句query 以及配置信息
  28. esutil.es_query_save(query, **db_config)
  29. def run():
  30. # 根据ES语句查找bidding
  31. es_query = {"track_total_hits": True,
  32. "query": {"bool": {"must": [{"range": {"publishtime": {"from": "1703001600", "to": "1703048399"}}}]}}}
  33. # es_query = {"track_total_hits": True,
  34. # "query": {"bool": {"must": [{"range": {"publishtime": {"from": "1691337600", "to": "1691424000"}}},
  35. # {"terms": {"subtype": ["中标", "合同","成交"]}}]}}}
  36. ES_bidding(es_query)
  37. run()