Elastic4s - 与Elasticsearch集群的HTTPS连接

时间:2017-05-31 14:25:41

标签: scala elasticsearch elastic4s

我正在尝试使用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客户端

     

DEBUG com.sksamuel.elastic4s.http.search.SearchImplicits $ SearchHttpExecutable $ - 执行搜索请求:{“查询”:{“匹配”:{“状态”:{“查询”:“已列出”}}}}

     

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

     

DEBUG com.sksamuel.elastic4s.http.search.SearchImplicits $ SearchHttpExecutable $ - {“query”:{“match”:{“status”:{“query”:“Listed”}}}}```< / p>

然后我明白了:

java.io.IOException: Connection reset by peer

并且未返回任何回复。

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

1 个答案:

答案 0 :(得分: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))