0

I'm having issues connecting to a local version of elasticsearch. I'm doing the following

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

But get a

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

exception. It doesn't matter if I go between 9200 / or 9300. ES is up and running correctly as far as I can see. Any pointers appreciated.

Steve
  • 21,163
  • 21
  • 69
  • 92

3 Answers3

0

In your local ElasticSearch instance, have you modified cluster.name in elasticsearch.yml? In that case you need to build Settings object.

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)
Pranav Shukla
  • 2,206
  • 2
  • 17
  • 20
0

There are some possible reasons for this:

  • The client and server versions can be different
  • Cluster name can be different
  • There could be a network problem when accesing the host and port.
alpert
  • 4,500
  • 1
  • 17
  • 27
-1

How to create elasticsearch 2.4.0 transport client using scala?

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 dependencies:

    <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>

output Result:

    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)
Adam
  • 4,445
  • 1
  • 31
  • 49
Samynathan
  • 51
  • 3