tobmei05
tobmei05

Reputation: 461

How to get health of an elasticsearch cluster using python API?

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

Upvotes: 5

Views: 10357

Answers (2)

Shajin Chandran
Shajin Chandran

Reputation: 1586

from elasticsearch import Elasticsearch
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
print(es.cat.health())

Upvotes: 3

Lilith Wittmann
Lilith Wittmann

Reputation: 383

You can't use the Cluster API directly, try this:

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

Upvotes: 11

Related Questions