Remote ElasticSearch cluster azure cloud connection using Python Client using http

660 views Asked by At

I'am having a trouble to connect the Python API to Elasticsearch. The Elasticsearch cluster is in azure cloud environment. This is what I tried:

from elasticsearch import Elasticsearch
es = Elasticsearch(
    "https://machine_name.kb.westeurope.azure.elastic-cloud.com:9200/",
    ca_certs="/path/to/http_ca.crt",
    api_key=("api_id",  "api_key")
)

However i can't ping the 'es' client. In fact the test return a None Object.

if not es.ping():
    print("No connection")
else:
    print(es.ping())

The code abose print "No connection". Can you please tell me what is wrong with my code ? There is another method using the Cloud ID. Where i can find the Cloud ID ?

Please Help, Thank you so much.

1

There are 1 answers

3
Paulo On

Tldr;

You are pinging Kibana's domain name not Elasticsearch. The domain name is wrong. You should take the Elasticsearch domain name.

To Solve

In your url you need to change machine_name.kb.westeurope to machine_name.es.westeurope

from elasticsearch import Elasticsearch
es = Elasticsearch(
    "https://machine_name.es.westeurope.azure.elastic-cloud.com:9200/",
    ca_certs="/path/to/http_ca.crt",
    api_key=("api_id",  "api_key")
)