Reputation: 415
I'm trying to connect to Elasticsearch using elastic4s-http vis https but can't find a way to use https instead of http.
I'm currently using:
HttpClient(ElasticsearchClientUri(config.getString("services.elasticsearch.host"), config.getInt("services.elasticsearch.port")))
to connect to the instance.
I seem to be getting a connection as I see this in the logs:
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"}}}}```
but then I get this:
java.io.IOException: Connection reset by peer
and no response is returned.
Any advice on how I can get https to work would be great, thanks
Upvotes: 1
Views: 1944
Reputation: 16387
You need version 5.4.4 or higher, and then you enable SSL on the connection string.
val uri = "elasticsearch://host:port,host:port,host:port?ssl=true"
val client = HttpClient(ElasticsearchClientUri(uri))
Or in your specific case:
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))
Upvotes: 1