0

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 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 で接続を受け入れます - https://www.elastic.co/guide/en/cloud/current/security.html#security-transport

さらに、選択した構築方法に応じてelasticsearch:\\、ホストとポートに a または append を探します。

私が得るクライアントを初期化する行さえ実行するとException in thread "main" java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)[Ljava/lang/Object;

明らかに私は何かを誤解しています。私が間違っていることを教えてください。

編集:

検証として、通常の http 接続を使用する ES への .Net クライアントがあります。

var node = new Uri(url);
var connectionSettings = new ConnectionSettings(node);
connectionSettings.BasicAuthentication(settings.username,settings.password);
client = new ElasticClient(connectionSettings);

私は同じことを達成することを目指しています。

4

1 に答える 1

0

依存関係に scala-library が欠けているように見えます。そのため、使用している Scala のバージョンに応じて、依存関係を一致させる必要があります。どのビルドツールを使用していますか?

SBT (これを行う必要はありません。SBT は scalaVersion に基づいて自動的に行う必要があります)

"org.scala-lang" % "scala-library" % "YOUR SCALA VERSION"

メイヴン

<dependency>
    <groupId>org.scala-lang</groupId>
    <artifactId>scala-library</artifactId>
    <version>2.12.1</version>
</dependency>

SBT には、 http: //www.scala-sbt.org/1.0/docs/Configuring-Scala.html にもいくつかの情報があります。

于 2017-01-04T13:08:51.300 に答える