收到此错误让我知道如何解决此问题。根据链接https://github.com/sksamuel/elastic4s,响应应为SearchResponse。
build sbt如下:
libraryDependencies += "com.sksamuel.elastic4s" % "elastic4s-core_2.11" % "2.2.0"
代码如下:
def searchItem(q: String): Future[SearchResponse] = {
val productsIndex = ESConfig.productsIndex
val rs = client.execute {
search in productsIndex / "items" query q
}
rs
}
错误如下:
[error] /home/shravan/Building_a_Recommendation_Engine_with_scala/src/main/scala/chapter07/ESUtil.scala:58: type mismatch;
[error] found : scala.concurrent.Future[com.sksamuel.elastic4s.RichSearchResponse]
[error] required: scala.concurrent.Future[org.elasticsearch.action.search.SearchResponse]
[error] rs
[error] ^
答案 0 :(得分:0)
在elatic4s
2.20 中,它构建了一个新模型RichSearchResponse
来替换原始的 elasticsearch SearchResponse
,以便于在Scala
,如果您仍需要获取原始 elasticsearch SearchResponse
,您可以这样做:
def searchItem(q: String): Future[RichSearchResponse] = {
val productsIndex = ESConfig.productsIndex
val rs = client.execute {
search in productsIndex / "items" query q
}
rs
}
val s: SearchResponse = Await(searchItem("test"), Duration.Inf).original
或
def searchItem(q: String): Future[SearchResponse] = {
val productsIndex = ESConfig.productsIndex
val rs = client.execute {
search in productsIndex / "items" query q
}
rs.map(s => s.original)
}