3

Am trying to get my hands on elastic4s by one of the samples as given here

But I keep getting the below exception when am trying to connect through TcpClient.transport :

Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{IFyYWnE_S4aHRVxT9v60LQ}{dockerhost}{192.168.99.100:9300}]]

Am trying to connect to an elastic instance on docker, elastic version is 2.3.4

Here is my code below dependencies.

import com.sksamuel.elastic4s.{ElasticClient, ElasticsearchClientUri, TcpClient}
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy
import org.elasticsearch.common.settings.Settings
import com.sksamuel.elastic4s.ElasticDsl._


object Main extends App {
  //val settings = Settings.builder().put("cluster.name", "elasticsearch").build()
  val client = TcpClient.transport(ElasticsearchClientUri("elasticsearch://dockerhost:9300"))

  client.execute {
  bulk(
    indexInto("myindex" / "mytype").fields("country" -> "Mongolia", "capital" -> "Ulaanbaatar"),
    indexInto("myindex" / "mytype").fields("country" -> "Namibia", "capital" -> "Windhoek")
  ).refresh(RefreshPolicy.WAIT_UNTIL)
  }.await

  val result = client.execute {
    search("myindex").matchQuery("capital", "ulaanbaatar")
  }.await

  println(result.hits.head.sourceAsString)

  client.close()
}

build.gradle:

compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-core_2.11', version: '5.4.9'
compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-tcp_2.11', version: '5.4.9'
compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-http_2.11', version: '5.4.9'
compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-streams_2.11', version: '5.4.9'

Any help regarding this issue would be helpful.

AdityaHandadi
  • 149
  • 1
  • 2
  • 13
  • 0 - Make sure port is available to host ( docker settings?) 1 - Are elasticsearch verions same ( Transport client and host ) – Nirmal Aug 08 '17 at 20:00
  • ports in the docker are exposed. elasticsearch versions meaning - 'elastic4s-tcp_2.11', version: '5.4.9' will not work against elasticsearch version 2.3.4? – AdityaHandadi Aug 08 '17 at 20:13
  • I tried with elastic4s-tcp_2.11 version 5.3.0 and elasticsearch 5.3.0, Still the same error – AdityaHandadi Aug 08 '17 at 20:20
  • Is your cluster name the default? If not, you need to specify it in the connection string. Also by default it might not bind outside of localhost, again you might need to set the publish host. – sksamuel Aug 17 '17 at 22:39

1 Answers1

1

I am asked this question a lot, and 99% of the time, the answer to this question is

  1. The cluster name is not the default (elasticsearch) and therefore it must be specified in the connection string.

  2. The server is not setup to listen outside of localhost. https://www.elastic.co/blog/elasticsearch-unplugged

sksamuel
  • 16,154
  • 8
  • 60
  • 108