elastic4s NoNodeAvailableException when connecting through TcpClient.transport

Viewed 260

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.

1 Answers
Related