【问题标题】:Scala Elastic4s can't find indexInto methodScala Elastic4s 找不到 indexInto 方法
【发布时间】:2018-04-21 07:00:17
【问题描述】:

我一直在寻求将弹性搜索集成到我的 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"
)

【问题讨论】:

标签: scala elasticsearch


【解决方案1】:

原来答案很简单,我只是忽略了它。更改此导入语句:

import com.sksamuel.elastic4s.ElasticDsl

收件人:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 2022-10-24
    相关资源
    最近更新 更多