【问题标题】:not found value index error on elastic4selastic4s上未找到值索引错误
【发布时间】:2014-03-14 20:32:24
【问题描述】:

我正在尝试使用elastic4s API 将一些数据索引到弹性搜索

但我收到编译错误not found: value index

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

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

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

还是别的什么??

感谢三木

【问题讨论】:

  • 看起来index 未定义为标识符,但很难说具体原因。请发布整个相关的sn-p和完全错误
  • @TheTerribleSwiftTomato 嗨,我添加了完整的错误
  • 我们还需要更多的代码来告诉你如何解决你的问题。
  • @TheTerribleSwiftTomato 我发布了完整的方法。

标签: scala elasticsearch elastic4s


【解决方案1】:

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

import com.sksamuel.elastic4s.ElasticDsl._

ElasticDsl module 是 elastic4s 的DSLs 的“入口点”,包括您使用的indexinto 方法的来源IndexDsl

除了你已经拥有的导入之外,上述导入是必要的,因为在 Scala import statements are not recursive

【讨论】:

    猜你喜欢
    • 2015-10-30
    • 2014-05-14
    • 2021-02-17
    • 2017-03-25
    • 2020-08-19
    • 1970-01-01
    • 1970-01-01
    • 2015-12-02
    • 2018-04-23
    相关资源
    最近更新 更多