pip3 install elasticsearch
# -*- coding: utf-8 -*-
from elasticsearch import Elasticsearch
# 查询索引中的所有内容
es = Elasticsearch([{'host':'172.16.xx.xx','port':9200}])
index = "logstash-nginx-access-2018.11.20"
query = {"query":{"match_all":{}}}
resp = es.search(index, body=query)
resp_docs = resp["hits"]["hits"]
total = resp['hits']['total']
print(total) #总共查找到的数量
print(resp_docs[0]['_source']['@timestamp']) #输出一个字段