es_api.py 779 B

1234567891011121314151617181920212223242526272829303132
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2023/8/9 10:41
  3. # @Author : XuJiakai
  4. # @File : es_api
  5. # @Software: PyCharm
  6. from data_clean.exception.fetch_exception import FetchException
  7. from data_clean.utils.async_client import get_aio_elasticsearch
  8. _es = get_aio_elasticsearch()
  9. async def search(index: str, body: dict, doc_type: str = '_doc') -> dict:
  10. try:
  11. return await _es.search(index=index, doc_type=doc_type, body=body)
  12. pass
  13. except Exception as ex:
  14. raise FetchException(ex)
  15. pass
  16. async def get(index: str, id: str, doc_type: str = '_doc') -> dict:
  17. try:
  18. return await _es.get(index=index, doc_type=doc_type, id=id)
  19. pass
  20. except Exception as ex:
  21. raise FetchException(ex)
  22. pass
  23. if __name__ == '__main__':
  24. pass