【问题标题】:Failed to establish connection error with elasticsearch无法使用elasticsearch建立连接错误
【发布时间】:2020-02-01 16:18:12
【问题描述】:

我一直在学习有关开发个性化语音助手的简单教程。为此,我正在使用 Elasticsearch。当我尝试运行代码时,我收到来自 elasticsearch 的错误消息 Failed to establish new connection。我不确定是什么导致了这个错误,因为我已经安装了 elasticsearch 及其 python 客户端。

我检查了我是否安装了弹性搜索及其 python 客户端,并且我已经完成了。我已经通过 pip3 安装安装了 python 客户端。我还检查了连接 U​​RL 是否正确,即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

编辑2: 现在,当我尝试在 erminal 中启动 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 命令来终止之前的所有操作开始了吗?

【问题讨论】:

  • 尝试使用http协议而不是url中的https。
  • 我做了,还是同样的错误。这个错误是否与我在终端中运行 Elasticsearch 时收到的错误相关联,它说 Error opening log file 'logs/gc.log': No such file or directory
  • 首先检查你的elasticsearch是否启动并运行通过检查它的服务状态并在你的浏览器中输入相同的url并检查你是否连接到你的ES。
  • 是的 elasaticsearch 已启动并运行,我已修复有关日志文件的错误,现在当我使用 http 协议时,我收到以下错误 raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) elasticsearch.exceptions.TransportError: &lt;exception str() failed&gt;
  • 会要求您在此处链接完整的错误日志,以及您要执行的操作。

标签: python python-3.x elasticsearch elastic-stack


【解决方案1】:

通过使用最新版本的 python-es 模块,问题得到了解决,因此最好升级模块。上述情况,之前使用的版本是2.4.0v,现在使用的最新版本是6.0.0v,问题就解决了。

【讨论】:

    猜你喜欢
    • 2020-08-28
    • 2020-05-09
    • 2017-10-12
    • 2016-12-28
    • 1970-01-01
    • 2014-12-16
    • 2022-04-25
    • 2017-05-14
    • 1970-01-01
    相关资源
    最近更新 更多