check elasticsearch connection status in python check elasticsearch connection status in python python python

check elasticsearch connection status in python


What you can do is call ping after creating the Elasticsearch instance, like this:

es = Elasticsearch(['http://localhost:9200/'], verify_certs=True)if not es.ping():    raise ValueError("Connection failed")


I had same urllib3.exceptions.ProtocolError issue, so made up for myself.

import requestsdef isRunning(self):    try:        res = requests.get("http://localhost:9200/_cluster/health")        if res.status_code == 200:            if res.json()['number_of_nodes'] > 0:                return True        return False    except Exception as e:        print(e)        return False