pip3 install elasticsearch
from elasticsearch import Elasticsearch
import pprint
es = Elasticsearch([{'host':'172.16.x.xx','port':9200}]) # es地址
index = "logstash-nginx-access-2019.05.15" # index索引名
doc = {
"query":{
"match_all":{}
}
}
res = es.search(index,body=doc) # 实例化
res_total = res['hits']['total']
res_docs = res["hits"]["hits"]
print('统计',res_total)
print('域名',res_docs[0]['_source']['server_name'])
print('索引',res_docs)
pprint.pprint(res_docs[0]['_source'], indent=3)