elastic4s org.elasticsearch.client.transport.NoNodeAvailableException:

时间:2016-05-06 16:46:41

标签: scala elasticsearch elastic4s

我在连接本地版本的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已正常启动并正常运行。任何指针都赞赏。

3 个答案:

答案 0 :(得分:0)

在您的本地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)

答案 1 :(得分:0)

有一些可能的原因:

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

答案 2 :(得分:-1)

如何使用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)