2

I am getting below error while using HttpClient. Can you let me know how to use HttpClient exactly. I am new with elastic4s. I want to connect scala with ssl configured elasticsearch. I also want to know how I can pass SSL details with link such as keystore path, truststore path and user name , password.

scala> import com.sksamuel.elastic4s.http.{HttpClient, HttpResponse}
import com.sksamuel.elastic4s.http.{HttpClient, HttpResponse}

scala> import com.sksamuel.elastic4s.http.ElasticDsl._
import com.sksamuel.elastic4s.http.ElasticDsl._

scala> val client = HttpClient(ElasticsearchClientUri(uri))
<console>:39: error: not found: value HttpClient
       val client = HttpClient(ElasticsearchClientUri(uri))

2 Answers2

1

HttpClient appears to be a trait in the codebase.You seem to be using the same as an object. You can check the implementation Here. For your use case i think the better approach would be to use ElasticClient. Code would look something like this

import com.sksamuel.elastic4s.http._
import com.sksamuel.elastic4s.{ElasticClient, ElasticDsl, ElasticsearchClientUri}
val client = elastic4s.ElasticClient(ElasticsearchClientUri(uri))
Rakshith
  • 644
  • 1
  • 8
  • 24
  • thank you so much, I have already tried it but didnt get any way to pass properties like certificate path and password of keystore etc. Can you please provide it and also I think there is one typo in your comment "ElasticClient" is part of com.sksamuel.elastic4s.http not com.sksamuel.elastic4s. –  Jul 18 '19 at 08:08
  • @Nakul- You have to use elastic4s-http dependency – user1668782 Aug 31 '19 at 13:03
  • @user1668782 Can you please share the code to pass truststore certificate path and password – Basant Jain May 21 '20 at 07:19
0

I got the same problem, i.e. in my setup I got errors (not found) when trying to use HttpClient (elastic4s-core,elastic4s-http-streams and elastic4s-client-esjava version 7.3.1 on scala 2.12.10).

The solution: you should be able to find and use JavaClient, an implementation of HttpClient that wraps the Elasticsearch Java Rest Client.

An example of how to use the JavaClient can be found here.

Thus, your code should look like the following:

import com.sksamuel.elastic4s.http.JavaClient
import com.sksamuel.elastic4s.{ElasticClient, ElasticDsl, ElasticProperties}
...
val client = ElasticClient(JavaClient(ElasticProperties(uri)))
vreyespue
  • 731
  • 9
  • 17