esQuery.py 1007 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. @author: Deepcold
  5. @file: esQuery.py
  6. @time: 2019/8/5 14:59
  7. """
  8. from elasticsearch import helpers, Elasticsearch
  9. from manage import CONFIG
  10. def es_query(query, index, doc_type):
  11. es_client = Elasticsearch(
  12. [CONFIG.ES_INFO.HOST], http_auth=(CONFIG.ES_INFO.USER, CONFIG.ES_INFO.PASSWD), port=CONFIG.ES_INFO.PORT,
  13. use_ssl=False, timeout=40)
  14. es_result = helpers.scan(client=es_client, query=query, scroll='10h',
  15. index=index, doc_type=doc_type, timeout='1m')
  16. return es_result
  17. def es_query_bg_name(event_company):
  18. query = {
  19. "query": {"bool": {
  20. "must": [
  21. {"match_phrase": {"yishen_bg": event_company}},
  22. {"term": {"end_susong_result": {"value": "胜"}}}],
  23. "must_not": [
  24. {"term": {"zhixing_result": {"value": "1"}}}]}}
  25. }
  26. query_content = es_query(query, "case_connect", "case_connect_type")
  27. return query_content