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']) #輸出一個字段