gpt4 book ai didi

scala - Scala Elastic4s找不到indexInto方法

转载 作者:行者123 更新时间:2023-12-02 23:59:54 24 4
gpt4 key购买 nike

我一直在试图将 flex 搜索集成到我的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"
)

最佳答案

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

import com.sksamuel.elastic4s.ElasticDsl

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

关于scala - Scala Elastic4s找不到indexInto方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49946974/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com