小编典典

在elastic4s上找不到值索引错误

elasticsearch

我试图通过使用elastic4s API 索引一些数据以进行elasticsearch

但是我正在编译错误 not found: value index

这是代码,稍后我将js对象字段映射到elasticsearch字段, 但是现在我只想索引一个测试用例

import com.sksamuel.elastic4s._
def indexComment(commentList: List[JsObject]) {
val client = ElasticClient.local
for (comment <- commentList) {
   val id = comment.\("id").as[String]   
   client.execute {
     index into "posts/test" id id.toString() fields (
      "name" -> "London",
      "country" -> "United Kingdom",
      "continent" -> "Europe",
      "status" -> "Awesome")
    }

   }

   }

  }

这是SBT文件

libraryDependencies ++= Seq( jdbc, anorm, cache, "org.webjars" %% "webjars- play" % "2.2.1", "org.webjars" % "bootstrap" % "3.1.0", "org.webjars" % "jquery" % "2.1.0-1", "com.sksamuel.elastic4s" %% "elastic4s" % "1.0.0.0" )

这是完全错误

[error] /home/mik/programing/posts/app/helper/Helper.scala:27: not found: value index [error] index into "posts/test" id id.toString() fields ( [error] ^ [error] one error found [error] (compile:compile) Compilation failed [error] Total time: 2 s, completed Feb 15, 2014 1:34:54 PM

我在安装过程中错过了什么吗?

还是其他?

谢谢miki


阅读 228

收藏
2020-06-22

共1个答案

小编典典

您的问题是缺少导入。作为链接状态的文档,
您还需要以下内容:

import com.sksamuel.elastic4s.ElasticDsl._

ElasticDsl模块是elastic4s
DSL的“入口点”
,包括您使用IndexDslindexinto方法的来源。

**除了您执行的导入之外,上述导入也是必需的,因为在Scala中,导入语句不是递归的

2020-06-22