Elasticsearch python client: Getting the ES version through API call
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))
You can achieve this using the info command:
Example:
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.info()