I am trying to connect elasticsearch in my local and I wonder how can I know the connection is successful or failed before continue to process: I wish it is possible with the way below I used but not(it returns too many values but all useless):
try:
es = Elasticsearch(['http://localhost:9200/'], verify_certs=True)
except Exception as err:
if "Connection refused" in err.message:
logging.error("Connection failed")
I hope there is a way to check connection status like this:
if es == false:
raise ValueError("Connection failed")