I have created an sbt project to learn how to use elastic search with akka. I came across alpakka
which provides this feature (to connect with elasticsearch).
According to docs, to search from ES we have following code:
val connectionSettings = ElasticsearchConnectionSettings("http://localhost:9200")
val sourceSettings = ElasticsearchSourceSettings(connectionSettings)
val elasticsearchParamsV7 = ElasticsearchParams.V7("index")
val copy = ElasticsearchSource
.typed[User](
elasticsearchParamsV7,
query = """{"match_all": {}}""",
sourceSettings
)
import spray.json.{DefaultJsonProtocol, RootJsonFormat}
case class User(first_name: String, last_name: String, email: String)
object MyJsonProtocol extends DefaultJsonProtocol {
implicit val userFormat: RootJsonFormat[User] = jsonFormat3(User)
}
What I found that an error showing related to spray json reader saying...
No implicits found for parameter sprayJsonReader: JsonReader[User]
I do not know what I am missing here.
I have already imported two libraries
"akka-http-spray-json"
"spray-json"
in build.sbt file
Your userFormat
isn't in scope for ElasticsearchSource.typed
, so import it, e.g.:
import MyJsonProtocol.userFormat
val copy = ElasticsearchSource.typed[User](
elasticsearchParamsV7,
query = """{ "match_all": {} }""",
sourceSettings
)