elasticsearch,Python 3.x,elasticsearch" /> elasticsearch,Python 3.x,elasticsearch" />

Python 3.x 如何使用python API获取elasticsearch集群的运行状况?

Python 3.x 如何使用python API获取elasticsearch集群的运行状况?,python-3.x,elasticsearch,Python 3.x,elasticsearch,我想获得与命令类似的elasticsearch集群的运行状况 curl -XGET 'http://localhost:9200/_cluster/health?pretty=true' 但是使用python。我做了以下几件事 from elasticsearch.client import ClusterClient esc = ClusterClient([{'host': 'localhost', 'port': 9200}]) esc.health(); 但我得到的只是一个 Attr

我想获得与命令类似的elasticsearch集群的运行状况

curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
但是使用python。我做了以下几件事

from elasticsearch.client import ClusterClient
esc = ClusterClient([{'host': 'localhost', 'port': 9200}])
esc.health();
但我得到的只是一个

AttributeError: 'list' object has no attribute 'transport'
我使用了health()的一些参数,比如索引和级别,但是我弄乱了语法。有人举了一个有效的例子吗

问候,,
Tobi

您不能直接使用群集API,请尝试以下方法:

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

print(es.cat.health())
对不起,这是我的第一篇文章。在文档中找到了一个条目:该实例具有属性cat、cluster、index、nodes和SnapshotClient,它们分别提供对CatClient、ClusterClient、IndicateSClient、NodeClient和SnapshotClient实例的访问。这是访问这些类及其方法的首选(也是唯一受支持的)方式。