1

我正在尝试将 ElasticSearch 与 Play 2.3.7 Scala 一起使用。我已经安装了弹性搜索,添加了一个索引,并让它运行起来(使用 curl 测试)。但是,我正在努力让 elastic4s 在播放控制器中工作。

我使用简单的远程 url 创建了客户端

val client = ElasticClient.remote("localhost", 9300)    

然后我尝试在客户端上执行。

client.execute {
    ElasticDsl.index.into("test/test").id(id).fields (
                    "title" -> title,
                    "uid" -> uid
    )
}

这是在 Action 内执行的,但出现以下错误。

could not find implicit value for parameter executable: com.sksamuel.elastic4s.Executable[com.sksamuel.elastic4s.IndexDefinition,R,Q]
4

1 回答 1

1

这似乎是因为我没有完全导入 ElasticDsl,如下所示

import com.sksamuel.elastic4s.ElasticDsl._ 

而是做

import com.sksamuel.elastic4s.ElasticDsl

导入完整对象时,它清楚地调用伴随对象,包括所需的隐式。

不进行完全导入的原因是,用于弹性的 DSL 与用于 Anorm 的 DSL 发生冲突,因此通过将弹性代码提取到单独的函数中,并在函数定义中使用导入,消除了歧义,并且代码能够编译。

于 2016-08-16T20:17:06.967 回答