1

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.

saad
  • 11
  • 3

1 Answers1

0

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")
)

Paulo
  • 8,690
  • 5
  • 20
  • 34
  • Many thanks for your anwser. I changed my code but the error still persist. I would like to use the Cloud Id like this: from elasticsearch import Elasticsearch # Password for the 'elastic' user generated by Elasticsearch ELASTIC_PASSWORD = "" # Found in the 'Manage Deployment' page CLOUD_ID = "deployment-name:dXMtZWFzdDQuZ2Nw..." # Create the client instance client = Elasticsearch( cloud_id=CLOUD_ID, basic_auth=("elastic", ELASTIC_PASSWORD) ) Where i can find the cloud id ? – saad May 10 '22 at 14:53
  • On your https://cloud.elastic.co/home console – Paulo May 10 '22 at 15:02
  • @saad, the cloud id can be found on your cloud.elastic.co console. If you do not have access to the console.. you won't have access to the cloud id – Paulo May 10 '22 at 16:50