我一直在关注有关开发个性化语音助手的简单教程。为此,我正在使用Elasticsearch。当我尝试运行代码时,elasticsearch提示Failed to establish new connection
时出错。我不确定是什么原因导致了此错误,因为我已经安装了elasticsearch及其python客户端。
我检查了我是否同时安装了弹性搜索及其python客户端,并且都已完成。我已经通过pip3安装安装了python客户端。我还检查了连接URL是否正确,例如https://localhost:9200/
。
我正在使用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'
实际错误消息是
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)
任何人都可以帮助我解决此错误。我是第一次使用Elasticsearch。
编辑:我试图在终端中运行elasticsearch,并且收到了以下警告,
OpenJDK 64-Bit Server VM warning: Cannot open file logs/gc.log due to No such file or directory
我进一步搜索了此警告,并找到了一个答案,提到它可能在弹性搜索中是错误的,我不确定,因为我使用的是最新版本。我提到的答案是
https://stackoverflow.com/questions/48696080/java-hotspottm-64-bit-server-vm-warning-cannot-open-file-logs-gc-log-due-to-no
Edit2: 现在,当我尝试在人体学上启动elasticsearch时,出现以下错误
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]
昨天我也遇到了同样的错误,但是当我重新启动系统时,它一切正常,是因为某种操作正在后面进行,并且它是否有任何特定的killall
命令来终止所有操作开始之前呢?
答案 0 :(得分:0)
通过使用最新版本的python-es模块,此问题已得到解决,因此最好升级该模块。在上述情况下,以前使用的版本是2.4.0v,现在使用的最新版本是6.0.0v,因此问题得以解决。