How to get cluster health using python API?


(Meier) #1

Hi all

I want to get the health of an elasticsearch cluster similar to the command

curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'

but using python. I did the following

from elasticsearch.client import ClusterClient
esc = ClusterClient([{'host': 'localhost', 'port': 9200}])
esc.health();

but all I get is an

AttributeError: 'list' object has no attribute 'transport'

I played around with some parameters for health() such us index and level but I mess around the syntax. Has someone a working example?

Regards,
Tobi


(Meier) #2

Got the answer from stackoverflow:

from elasticsearch import Elasticsearch
es = Elasticsearch()
print(es.cluster.health())

(system) #3