Scala Elastic4s java.lang.NoSuchMethodError
我正试图通过Elastic4s连接到ES群集。我正在使用github回购协议中给出的示例:Scala Elastic4s java.lang.NoSuchMethodError,scala,elasticsearch,elastic4s,Scala,elasticsearch,Elastic4s,我正试图通过Elastic4s连接到ES群集。我正在使用github回购协议中给出的示例: import com.sksamuel.elastic4s.ElasticClient import com.sksamuel.elastic4s.ElasticDsl._ object Test extends App { val client = ElasticClient.transport(ElasticsearchClientUri(host, port)) // await is
import com.sksamuel.elastic4s.ElasticClient
import com.sksamuel.elastic4s.ElasticDsl._
object Test extends App {
val client = ElasticClient.transport(ElasticsearchClientUri(host, port))
// await is a helper method to make this operation synchronous instead of async
// You would normally avoid doing this in a real program as it will block your thread
client.execute { index into "bands" / "artists" fields "name"->"coldplay" }.await
// we need to wait until the index operation has been flushed by the server.
// this is an important point - when the index future completes, that doesn't mean that the doc
// is necessarily searchable. It simply means the server has processed your request and the doc is
// queued to be flushed to the indexes. Elasticsearch is eventually consistent.
// For this demo, we'll simply wait for 2 seconds (default refresh interval is 1 second).
Thread.sleep(2000)
// now we can search for the document we indexed earlier
val resp = client.execute { search in "bands" / "artists" query "coldplay" }.await
println(resp)
}
客户端接受9434上的连接,如下所述-
此外,它会根据所选的构造方式,查找或附加到主机和端口的elasticsearch:\\\
在运行初始化客户机的行时,我在线程“main”java.lang.NoSuchMethodError:scala.Predef$.refArrayOps([Ljava/lang/Object;)[Ljava/lang/Object;
很明显我误解了什么。请让我知道我做错了什么
编辑:
作为验证,我有一个到ES的.Net客户端,它使用常规http连接
var node = new Uri(url);
var connectionSettings = new ConnectionSettings(node);
connectionSettings.BasicAuthentication(settings.username,settings.password);
client = new ElasticClient(connectionSettings);
我的目标是实现同样的目标。看起来您的依赖项中缺少scala库。因此,根据您使用的scala版本,您必须让DEP与之匹配。您使用的是什么构建工具 SBT(您不需要这样做,SBT应该根据您的喜好自动完成) 马文
org.scala-lang
"org.scala-lang" % "scala-library" % "YOUR SCALA VERSION"
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.12.1</version>
</dependency>