elastic4s org.elasticsearch.client.transport.NoNodeAvailableException:

elastic4s org.elasticsearch.client.transport.NoNodeAvailableException:

我在连接本地版本的 elasticsearch 时遇到问题。我正在执行以下操作

val uri = ElasticsearchClientUri("elasticsearch://127.0.0.1:9300")
val client = ElasticClient.remote(uri)
lient execute { search in "_all" query "test" }

但是得到一个

org.elasticsearch.client.transport.NoNodeAvailableException: None of the    configured nodes are available: []

异常。我在 9200 / 或 9300 之间移动并不重要。据我所知,ES 已经启动并且 运行 正确。任何指点表示赞赏。

在您的本地 ElasticSearch 实例中,您是否在 elasticsearch.yml 中修改了 cluster.name?在这种情况下,您需要构建 Settings 对象。

val settings = Settings.settingsBuilder().put("cluster.name", "cluster_name").build()    // set cluster_name to cluster.name from your elasticsearch.yml
val uri = ElasticsearchClientUri("elasticsearch://127.0.0.1:9300")
client = ElasticClient.remote(settings, uri)

可能有以下原因:

  • 客户端和服务器版本可以不同
  • 集群名称可以不同
  • 访问主机和端口时可能存在网络问题。

如何使用scala创建elasticsearch 2.4.0传输客户端?

import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.{ElasticsearchClientUri, ElasticClient}
import org.elasticsearch.common.settings.Settings    
object Facebook {
        def main(args: Array[String]) {


    val settings = Settings.builder().put("cluster.name", "myClusterName").build()
    val client = ElasticClient.transport(settings, ElasticsearchClientUri("elasticsearch://localhost:9300"))
          client.execute { createIndex("places") shards 3 replicas 2 }
        }
    }

scala maven 依赖项:

    <dependency>
        <groupId>com.sksamuel.elastic4s</groupId>
        <artifactId>elastic4s-core_2.11</artifactId>
        <version>2.4.0</version>
    </dependency>

    <dependency>
        <groupId>com.sksamuel.elastic4s</groupId>
        <artifactId>elastic4s-tcp_2.11</artifactId>
        <version>5.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>2.4.0</version>
    </dependency>

输出结果:

    log4j:WARN No appenders could be found for logger (org.elasticsearch.plugins).
    log4j:WARN Please initialize the log4j system properly.
    log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
    Exception in thread "main" java.lang.NoSuchFieldError: LUCENE_4_0_0
        at org.elasticsearch.Version.<clinit>(Version.java:44)
        at org.elasticsearch.client.transport.TransportClient$Builder.build(TransportClient.java:129)
        at com.sksamuel.elastic4s.ElasticClient$.transport(ElasticClient.scala:112)
        at example.Facebook$.main(Facebook.scala:23)
        at example.Facebook.main(Facebook.scala)