Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to establish a new connection: [Errno 111] Connection refused(elasticsearch)

I have installed elasticsearch using this command : pip install elasticsearch After installation I executed the following commands:

>>> from datetime import datetime
>>> from elasticsearch import Elasticsearch
# by default we connect to localhost:9200
>>> es = Elasticsearch()
# create an index in elasticsearch, ignore status code 400 (index already exists)
# but when I run this instruction:
>>> es.indices.create(index='my-index', ignore=400) // HERE IS THE PROBLEM

I get this error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "elasticsearch/client/utils.py", line 69, in _wrapped
return func(*args, params=params, **kwargs)
File "elasticsearch/client/indices.py", line 110, in create
params=params, body=body)
File "elasticsearch/transport.py", line 327, in perform_request
status, headers, data = connection.perform_request(\
    method, url, params, body, ignore=ignore, timeout=timeout)
File "elasticsearch/connection/http_urllib3.py", line 105, in perform_request
raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError:
    ConnectionError(<urllib3.connection.HTTPConnection object at 0xM3M>:
        Failed to establish a new connection: [Errno 111] Connection refused) caused by:
            NewConnectionError(<urllib3.connection.HTTPConnection object at 0xM3M>:
                Failed to establish a new connection: [Errno 111] Connection refused)
like image 968
Waheeb Al-Abyadh Avatar asked Sep 12 '16 09:09

Waheeb Al-Abyadh


1 Answers

What you have installed is a Python client which is used for communication between your Python script and existing Elasticsearch cluster.

As mentioned from your comment, at the top of the page you started reading, it says:

Official low-level client for Elasticsearch. Its goal is to provide common ground for all Elasticsearch-related code in Python; because of this it tries to be opinion-free and very extendable.

You can configure the client the host(s) and port which the cluster is running on, and connect to it and execute commands on that cluster.

In your code, you configured the client to use the default settings which assumes the cluster is running on localhost with the default elasticsearch port 9200.

You need to Install Elasticsearch on a machine, configure it and run it, and then you'll be able to connect your client to the cluster and communicate with it.

like image 178
Avihoo Mamka Avatar answered Sep 21 '22 09:09

Avihoo Mamka