【问题标题】:Elastic4s - HTTPS connection to Elasticsearch clusterElastic4s - 到 Elasticsearch 集群的 HTTPS 连接
【发布时间】:2017-05-31 14:25:41
【问题描述】:

我正在尝试使用 elastic4s-http vis https 连接到 Elasticsearch,但找不到使用 https 代替 http 的方法。

我目前正在使用:

HttpClient(ElasticsearchClientUri(config.getString("services.elasticsearch.host"), config.getInt("services.elasticsearch.port")))

连接到实例。

当我在日志中看到这一点时,我似乎正在建立连接:

INFO com.sksamuel.elastic4s.http.HttpClient$ - 在 http://host:port 上创建 HTTP 客户端

调试 com.sksamuel.elastic4s.http.search.SearchImplicits$SearchHttpExecutable$ - 执行搜索请求:{"query":{"match":{"status":{"query":"Listed"}}}}

调试 com.sksamuel.elastic4s.http.search.SearchImplicits$SearchHttpExecutable$ - 执行弹性请求 POST:/myindex/_search?

调试 com.sksamuel.elastic4s.http.search.SearchImplicits$SearchHttpExecutable$ - {"query":{"match":{"status":{"query":"Listed"}}}}```

但后来我明白了:

java.io.IOException: Connection reset by peer

并且没有返回任何响应。

任何关于如何让 https 工作的建议都会很棒,谢谢

【问题讨论】:

    标签: scala elasticsearch elastic4s


    【解决方案1】:

    您需要 5.4.4 或更高版本,然后在连接字符串上启用 SSL。

    val uri = "elasticsearch://host:port,host:port,host:port?ssl=true"
    val client = HttpClient(ElasticsearchClientUri(uri))
    

    或者在您的具体情况下:

    val host = config.getString("services.elasticsearch.host")
    val port = config.getString("services.elasticsearch.port")
    val uri = s"elasticsearch://$host:$port?ssl=true"
    val client = HttpClient(ElasticsearchClientUri(uri))
    

    【讨论】:

    • 有没有办法通过这个设置通过身份验证用户/密码?
    • 您可以在最新版本中使用elasticsearch://user:name@host:port,host:port,host:port?ssl=true
    猜你喜欢
    • 2020-07-12
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 2020-08-26
    • 2021-09-23
    • 1970-01-01
    相关资源
    最近更新 更多