5

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

2 Answers 2

11

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

from elasticsearch import Elasticsearch
es = Elasticsearch()
print(es.cluster.health())
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, was my first post.
Found an entry in the documentation: The instance has attributes cat, cluster, indices, nodes and snapshot that provide access to instances of CatClient, ClusterClient, IndicesClient, NodesClient and SnapshotClient respectively. This is the preferred (and only supported) way to get access to those classes and their methods.
3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.