Scala Elastic4s无法找到indexInto方法

时间:2018-04-20 17:32:10

标签: scala elasticsearch

我一直在寻求将弹性搜索集成到我的Scala程序中,但它始终难以找到某些方法和值。在这种情况下,它找不到indexTo和' /'在堆栈跟踪中提到的字符串中。我认为这是进口的一个问题,但我仍然是该语言的新手。任何帮助表示赞赏!

堆栈追踪:

[error] /Users/khalid/prog/decision_tree/src/main/scala/IrisClassifier2.scala:60:13: not found: value indexInto
[error]             indexInto("myindex" / "mytype").fields("s_length" -> (Json.parse(n) \ "sipJson" \ "s_length").as[Double],
[error]             ^
[error] /Users/khalid/prog/decision_tree/src/main/scala/IrisClassifier2.scala:60:33: value / is not a member of String
[error]             indexInto("myindex" / "mytype").fields("s_length" -> (Json.parse(n) \ "sipJson" \ "s_length").as[Double],
[error]                                 ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed

代码失败的对象内的主代码:

import com.sksamuel.elastic4s.ElasticsearchClientUri
import com.sksamuel.elastic4s.http.HttpClient
import com.sksamuel.elastic4s.http.search.SearchResponse
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy
import com.sksamuel.elastic4s.ElasticDsl

val client = HttpClient(ElasticsearchClientUri("localhost", 9200))

client.execute {
        indexInto("myindex" / "mytype").fields("s_length" -> (Json.parse(n) \ "sipJson" \ "s_length").as[Double],
                                                 "s_width" -> (Json.parse(n) \ "sipJson" \ "s_width").as[Double],
                                                 "p_length" -> (Json.parse(n) \ "sipJson" \ "p_length").as[Double],
                                                 "p_width" -> (Json.parse(n) \ "sipJson" \ "p_width").as[Double],
                                                 "result" -> labelMap(model.predict(input)))
        .refresh(RefreshPolicy.WAIT_UNTIL)
    }.await

Build.sbt文件:

name := "SparkDT"

version := "0.1"

scalaVersion := "2.11.8"

val sparkVersion = "2.2.0"
val elastic4sVersion = "5.6.5"

dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-core" % "2.8.7"
dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-databind" % "2.8.7"
dependencyOverrides += "com.fasterxml.jackson.module" % "jackson-module-scala_2.11" % "2.8.7"

libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % sparkVersion,
  "org.apache.spark" %% "spark-mllib" % sparkVersion,
  "com.typesafe.play" %% "play-json" % "2.6.7",
  "com.sksamuel.elastic4s" %% "elastic4s-core" % elastic4sVersion,
  "com.sksamuel.elastic4s" %% "elastic4s-http" % elastic4sVersion,
  "com.sksamuel.elastic4s" %% "elastic4s-streams" % "5.6.5",
  "com.sksamuel.elastic4s" %% "elastic4s-testkit" % elastic4sVersion % "test",
  "com.sksamuel.elastic4s" %% "elastic4s-embedded" % elastic4sVersion % "test"
)

1 个答案:

答案 0 :(得分:0)

事实证明答案很简单,我只是忽略了它。更改此导入语句:

import com.sksamuel.elastic4s.ElasticDsl

要:

import com.sksamuel.elastic4s.http.ElasticDsl._