es.py 594 B

1234567891011121314151617181920212223242526272829
  1. import datetime
  2. import json
  3. from elasticsearch import Elasticsearch
  4. from elasticsearch import helpers
  5. index_name = 'eip_rec_feed'
  6. es = Elasticsearch(
  7. ['http://eip-es-3.mlamp.cn:9200/'],
  8. http_auth=('recommend', '=FhULOxd'),
  9. port=9200,
  10. use_ssl=False
  11. )
  12. print("索引情况")
  13. print(es.cat.indices())
  14. #
  15. print("mapping情况")
  16. res = es.indices.get_mapping(index=index_name)
  17. print(json.dumps(res, indent=2))
  18. print("查询情况")
  19. body = {
  20. "query": {
  21. "match_all": {}
  22. }
  23. }
  24. res = es.search(index=index_name, doc_type="_doc", body=body)
  25. print(json.dumps(res, indent=2))