Sai Raghava
Sai Raghava

Reputation: 137

Failed to establish connection error with elasticsearch

I have been following a simple tutorial about developing a personalized voice assistant. For that, I am using Elasticsearch. when I try to run the code, I get an error from elasticsearch saying Failed to establish new connection. I am not sure what is causing this error as I have installed both elasticsearch as well as its python client.

I have checked whether I have installed both elastic search and its python client and i have done it. I have installed python client through pip3 installation. I have also checked whether the connection URL and i believe it is correct i.e. https://localhost:9200/.

I am using macOS.

s = Elasticsearch(['https://localhost:9200/'])
bulk(es, records, index='voice_assistant', doc_type='text', raise_on_error=True)
def search_es(query):
    res = es.search(index="voice_assistant", doc_type="text", body={                     
    "query" :{
        "match": {
            "voice_command": {
                "query": query,
                "fuzziness": 2
            }
            }
        },
    })
    return res['hits']['hits'][0]['_source']['sys_command'

The actual error message is

File "/usr/local/lib/python3.7/site-packages/elasticsearch/connection/http_urllib3.py", line 105, in perform_request
    raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.VerifiedHTTPSConnection object at 0x1266dce10>: Failed to establish a new connection: [Errno 61] Connection refused) caused by: NewConnectionError(<urllib3.connection.VerifiedHTTPSConnection object at 0x1266dce10>: Failed to establish a new connection: [Errno 61] Connection refused)

Can anyone please help me fix this error. I am using elasticsearch for the first time.

EDIT: I have tried to run elasticsearch in terminal and I have got this following warning,

OpenJDK 64-Bit Server VM warning: Cannot open file logs/gc.log due to No such file or directory

I have googled further about this waring and found an answer mentioning it probably might be ab ug in elastic search which I am not sure as I am using the latest version. The answer I was mentioning is

https://stackoverflow.com/questions/48696080/java-hotspottm-64-bit-server-vm-warning-cannot-open-file-logs-gc-log-due-to-no

Edit2: Now when i try to launch elasticsearch in erminal i get the following error

StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/local/var/lib/elasticsearch]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.4.0.jar:7.4.0]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.4.0.jar:7.4.0]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.4.0.jar:7.4.0]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125) ~[elasticsearch-cli-7.4.0.jar:7.4.0]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.4.0.jar:7.4.0]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.4.0.jar:7.4.0]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.4.0.jar:7.4.0]

I got the same error yesterday as well but when I restarted my system, it all works fine, is it because that some kind of operation is running behind and does it have any specific killall command to terminate all the operations before starting it?

Upvotes: 0

Views: 4456

Answers (1)

Yash Tandon
Yash Tandon

Reputation: 475

well by using the latest version of python-es module the issue got resolved so its better to upgrade the module. In the above case the previous version being used was 2.4.0v and the latest version now being used is 6.0.0v, hence the problem got resolved.

Upvotes: 1

Related Questions