0

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?

Sai Raghava
  • 147
  • 1
  • 4
  • 13
  • try to connect with http protocol and not https in the url. – Yash Tandon Oct 03 '19 at 10:55
  • I did, it was the same error. Isn't this error linked to the error I have received while trying to run Elasticsearch in terminal, it says ```Error opening log file 'logs/gc.log': No such file or directory``` – Sai Raghava Oct 03 '19 at 11:05
  • first of all first check if your elasticsearch is up and running by cheking its service status and type the same url in your browser and check if you are connected to your ES or not. – Yash Tandon Oct 03 '19 at 11:45
  • yes elasaticsearch is up and running, i have fixed the error regarding log file and now when i usee http protocol i get following error ```raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) elasticsearch.exceptions.TransportError: ``` – Sai Raghava Oct 03 '19 at 13:23
  • would request you to link your complete error log here, and what you are trying to do. – Yash Tandon Oct 04 '19 at 04:49
  • I am having a specific operation where it says node is already in use, I have updated it in the answer part edit2, I got the similar error last night and when I restarted my system it worked fine, – Sai Raghava Oct 04 '19 at 06:16
  • I have fixed that error, I have updated the python-es module to the latest version and the error is fixed. I believe it is some kind of bug in the older version. – Sai Raghava Oct 09 '19 at 07:42
  • may have been some compatibility issue, good to know that the issue is resolved tell me the latest version which you are using for the module so that i post it in the answers so that it could be helpful for others. – Yash Tandon Oct 09 '19 at 09:25
  • yea, I updated it to elastic search 6.0.0 , previously i was using elastic search 2.4.0 – Sai Raghava Oct 13 '19 at 09:49

1 Answers1

1

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.

Yash Tandon
  • 345
  • 5
  • 18