es.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # author : liumiaomiao
  4. #从es库中导出数据到测试环境mongo库
  5. from lib.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': 19800,
  15. 'es_http_auth': ('jianyuGr','we3g8glKfe#'), # 重新申请
  16. 'timeout': 10000,
  17. # 'index': "projectset",
  18. 'index': "bidding",
  19. 'size': 1000,
  20. # mongo存的数据库表
  21. 'mg_host': '172.20.45.129',
  22. 'mg_port': 27002,
  23. 'database': 'data_quality',
  24. 'collection': 'bidding_20250515_fujian'
  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": {
  33. "bool": {
  34. "must": [{
  35. "range": {
  36. "publishtime": {
  37. "gte": 1747238400,
  38. "lte": 1747324800
  39. }
  40. }
  41. }, {
  42. "bool": {
  43. "must": [{
  44. "multi_match": {
  45. "query": "详见附件",
  46. "type": "phrase",
  47. "fields": ["detail"]
  48. }
  49. }]
  50. }
  51. }],
  52. "must_not": []
  53. }
  54. },
  55. "highlight": {
  56. "pre_tags": [""],
  57. "post_tags": [""],
  58. "fields": {
  59. "detail": {
  60. "fragment_size": 115,
  61. "number_of_fragments": 1
  62. }
  63. }
  64. },
  65. "sort": [{
  66. "dataweight": "desc"
  67. }, {
  68. "publishtime": "desc"
  69. }],
  70. "from": 0
  71. }
  72. # es_query = {"track_total_hits": True,
  73. # "query": {"bool": {"must": [{"range": {"comeintime": {"from": "1747324800", "to": "1747411200"}}}]}}}
  74. # es_query = {"track_total_hits": True,
  75. # "query": {"bool": {"must": [{"range": {"publishtime": {"from": "1691337600", "to": "1691424000"}}},
  76. # {"terms": {"subtype": ["中标", "合同","成交"]}}]}}}
  77. ES_bidding(es_query)
  78. run()