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)
OPTION 1: Check Version using Curl from Command Line In this example, Elasticsearch is running locally on the default port so our HTTP request will be to http://localhost:9200 . If Elasticsearch was running on a different server your HTTP request would take the form http://YOURDOMAIN.com:9200 .
Elasticsearch is a powerful open source search and analytics engine that makes data easy to explore. Doc_type is a field in Elasticsearch that allows you to specify the type of document you are indexing. This is useful for when you have multiple types of documents in the same index.
You can achieve this using the info command:
Example:
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.info()
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With