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.
CodePudding user response:
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")
)
CodePudding user response:
@Paulo 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 = "<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 ?