Python elisticsearch client: getting ES version via API call

I want to get the current version of Elasticsearch through the Python API. I could easily get this through an HTTP call, like

import requests
requests.get(http://endpoint:9200)

But I'm wondering if there is a way to get the version through an API call instead of an http request to the endpoint. like

from elasticsearch import Elasticsearch
es = Elasticsearch()

I looked at the Python client documentation for Elasticsearch, but couldn't find a call that would retrieve the current version of ES ( https://elasticsearch-py.readthedocs.org/en/master/api.html ).

+5
source share
2 answers

This can be done using the info command :

Example:

from elasticsearch import Elasticsearch
es = Elasticsearch()
es.info()
+6
source

If you only want to get version number, you can do something like this:

def get_cluster_version(server, user, password):
cluster_version = "version"

r = do_request(verb='get',
               server='http://{0}'.format(server),
               auth=(user, password),
               verify=False)
json_data = json.loads(r.content.decode('utf8'))
version_number = str(json_data["version"]["number"])
logging.info("Elastic cluster version " + str(version_number))
0
source

All Articles