13

I want to get the current Elasticsearch version through the python API. I could easily get it through a http call like

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

But I am wondering is there any way to get the version through the API call instead of http request to the endpoint. Like

from elasticsearch import Elasticsearch
es = Elasticsearch()

I went through the Elasticsearch python client documentation, but couldn't find the call that would fetch the current ES version (https://elasticsearch-py.readthedocs.org/en/master/api.html)

3 Answers 3

22

You can achieve this using the info command:

Example:

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

Comments

2

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

#/usr/bin/env python
import json
import logging
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))

Comments

0

This worked for me, returns the version number:

client = Elasticsearch(cloud_id=self.cloud_id, http_auth=self.auth)
return client.info()['version']['number']

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.