Hello,
I'm receiving the following error when trying to use the example code:
elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x10896f290>: Failed to establish a new connection: [Errno 61] Connection refused) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x10896f290>: Failed to establish a new connection: [Errno 61] Connection refused)
I've verified that the elasticsearch server is running and that I'm able to use it via cURL / browser. For example, cURLing, I get the following response:
{
"name" : "LONG STRING",
"cluster_name" : "CHANGED CLUSTER NAME",
"cluster_uuid" : "CHANGED UUID",
"version" : {
"number" : "5.1.1",
"build_hash" : "5395e21",
"build_date" : "2016-12-06T12:36:15.409Z",
"build_snapshot" : false,
"lucene_version" : "6.3.0"
},
"tagline" : "You Know, for Search"
}
Hi, could you please share the code for the curl command that works and also how you instantiate the client? Without it it's impossible to tell what could be wrong.
Thanks!
Hi, The curl command I'm running is the following:
curl -XGET 'our.es.server.name'
This is the code I'm using to instantiate the client (Default connection):
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
from elasticsearch_dsl.connections import connections
connections.create_connection(hosts=['our.es.server.name'], timeout=20)
client = Elasticsearch()
s = Search(using=client, index="changed.index") \
.query("match", env="changed.environment")
response = s.execute()
for hit in response:
print(hit.meta.score, hit.title)
Manual connection:
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
client = Elasticsearch('our.es.server.name')
s = Search(using=client, index="changed.index") \
.query("match", env="changed.environment")
response = s.execute()
for hit in response:
print(hit.meta.score, hit.title)
In that case the problem is that curl defaults to port 80 while Elasticsearch to port 9200, you need to specify the port by using our.es.server.name:9200
@HonzaKral That is not the solution.
"our.es.server.name" must be listening to 9200 instead of 80. or else the curl -XGET 'our.es.server.name' would not have returned "tagline" : "You Know, for Search". assigning port in front of domain name will not fix the issue.
The firewall is blocking the domain access. The alternative would be port forwarding.
Thanks
Most helpful comment
In that case the problem is that
curldefaults to port80whileElasticsearchto port9200, you need to specify the port by usingour.es.server.name:9200