Search code examples
pythonelasticsearchelastic-stackelasticsearch-dsl

elasticsearch on python gives name or service not known


I'm working with an elastic API on a url like https://something.xyzw.eg/api/search/advance (not the real url). The API works fine on postman. Also the python code generated by postman works fine and returns results. However when using leasticsearch-dsl package I keep getting:

Failed to establish a new connection: [Errno -2] Name or service not known)

Here is my code similar to the first example on documents:

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search

client = Elasticsearch(host='https://something.xyzw.eg/api/search/advance')
s = Search(using=client)    
response = s.execute()

Any idea what I'm doing wrong?


Edit:

Apparently host shouldn't contain a url, but a hostname. However, I don't have any control on where the API is. Is there a workaround to get elasticsearch to work with url?


Solution

  • For reference: it turned out that the API I was using wasn't in fact the standard ElasticSearch, but would proxy my request to the ElasticSearch. So sending requests by postman and requests package would work (as the requsets were sent to Elastic), but elasticsearch-py couldn't connect to it (since the route I was trying to connect to wasn't actually Elastic itself).