Elastic4s - 到 Elasticsearch 集群的 HTTPS 连接
Elastic4s - HTTPS connection to Elasticsearch cluster
我正在尝试使用 elastic4s-http 相对于 https 连接到 Elasticsearch,但找不到使用 https 代替 http 的方法。
我目前正在使用:
HttpClient(ElasticsearchClientUri(config.getString("services.elasticsearch.host"), config.getInt("services.elasticsearch.port")))
连接到实例。
我似乎正在建立连接,因为我在日志中看到了这一点:
INFO com.sksamuel.elastic4s.http.HttpClient$ - Creating HTTP client on http://host:port
DEBUG com.sksamuel.elastic4s.http.search.SearchImplicits$SearchHttpExecutable$ - Executing search request: {"query":{"match":{"status":{"query":"Listed"}}}}
DEBUG com.sksamuel.elastic4s.http.search.SearchImplicits$SearchHttpExecutable$ - Executing elastic request POST:/myindex/_search?
DEBUG com.sksamuel.elastic4s.http.search.SearchImplicits$SearchHttpExecutable$ - {"query":{"match":{"status":{"query":"Listed"}}}}```
但后来我明白了:
java.io.IOException: Connection reset by peer
并且没有返回任何响应。
任何关于如何让 https 工作的建议都很好,谢谢
您需要 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))
我正在尝试使用 elastic4s-http 相对于 https 连接到 Elasticsearch,但找不到使用 https 代替 http 的方法。
我目前正在使用:
HttpClient(ElasticsearchClientUri(config.getString("services.elasticsearch.host"), config.getInt("services.elasticsearch.port")))
连接到实例。
我似乎正在建立连接,因为我在日志中看到了这一点:
INFO com.sksamuel.elastic4s.http.HttpClient$ - Creating HTTP client on http://host:port
DEBUG com.sksamuel.elastic4s.http.search.SearchImplicits$SearchHttpExecutable$ - Executing search request: {"query":{"match":{"status":{"query":"Listed"}}}}
DEBUG com.sksamuel.elastic4s.http.search.SearchImplicits$SearchHttpExecutable$ - Executing elastic request POST:/myindex/_search?
DEBUG com.sksamuel.elastic4s.http.search.SearchImplicits$SearchHttpExecutable$ - {"query":{"match":{"status":{"query":"Listed"}}}}```
但后来我明白了:
java.io.IOException: Connection reset by peer
并且没有返回任何响应。
任何关于如何让 https 工作的建议都很好,谢谢
您需要 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))