Search code examples
scalaelasticsearchelastic4s

not found value index error on elastic4s


im trying to index some data to elastic search by using the elastic4s API

but im getting compile error not found: value index

this is the code , later on i will map the js object fields to the elastic search fields , but for now i just want to index a test case

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")
    }

   }

   }

  }

and this is the SBT file

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"
)

and this is the complete error

[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

did i miss something in the installation process ??

or it`s something else ??

thanks miki


Solution

  • Your problem is a missing import. As the documentation you linked states, you also need the following:

    import com.sksamuel.elastic4s.ElasticDsl._
    

    The ElasticDsl module is an "entry point" for elastic4s' DSLs, including the IndexDsl from where the index and into methods that you use come from.

    The aforementioned import is necessary in addition to the one you do have because in Scala import statements are not recursive.