python 查询ElasticSearch 中索引的doc

2020-05-13  本文已影响0人  HAO延WEI
from elasticsearch import Elasticsearch, helpers

def elasticsearch(index):
    es = Elasticsearch(['http://localhost:80'],
                       sniff_on_start=True,
                       sniff_on_connection_fail=True,
                       sniff_timeout=60)
    es.cluster = "bdp-es6"
    data = es.count(index=index, doc_type="reptile")
    print data
    if data:
        return data['count']
if __name__ == '__main__':
    elasticsearch("test")   

效果

上一篇下一篇

猜你喜欢

热点阅读