1

我正在尝试使用 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 工作的任何建议都会很棒,谢谢

4

1 回答 1

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))
于 2017-06-10T02:54:24.853 回答