scala org.elasticsearch.client.transport.NoNodeAvailableException:没有配置的节点可用:[]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32277401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
提问by daydreamer
I am running ElasticSearchon Dockerwhich is available locally as
我正在ElasticSearch上Docker它可为本地
$ curl http://192.168.99.100:9200/?pretty
{
"status" : 200,
"name" : "Collector",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "1.4.4",
"build_hash" : "c88f77ffc81301dfa9dfd81ca2232f09588bd512",
"build_timestamp" : "2015-02-19T13:05:36Z",
"build_snapshot" : false,
"lucene_version" : "4.10.3"
},
"tagline" : "You Know, for Search"
}
I am using Elastic4s, for connecting to ElasticSearch, I tried following approach, but all of them gave me error as
我正在使用Elastic4s,为了连接到ElasticSearch,我尝试了以下方法,但所有这些都给了我错误
val client = ElasticClient.remote(host = "192.168.99.100", port = 9200)
and
和
val settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch").build()
val uri = ElasticsearchClientUri("elasticsearch://192.168.99.100:9200")
val client = ElasticClient.remote(uri)
The error is
错误是
Exception in thread "main" org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:305)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:200)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)
at org.elasticsearch.client.support.AbstractClient.index(AbstractClient.java:102)
at org.elasticsearch.client.transport.TransportClient.index(TransportClient.java:340)
at com.sksamuel.elastic4s.IndexDsl$IndexDefinitionExecutable$$anonfun$apply.apply(IndexDsl.scala:23)
at com.sksamuel.elastic4s.IndexDsl$IndexDefinitionExecutable$$anonfun$apply.apply(IndexDsl.scala:23)
at com.sksamuel.elastic4s.Executable$class.injectFuture(Executable.scala:21)
at com.sksamuel.elastic4s.IndexDsl$IndexDefinitionExecutable$.injectFuture(IndexDsl.scala:20)
at com.sksamuel.elastic4s.IndexDsl$IndexDefinitionExecutable$.apply(IndexDsl.scala:23)
at com.sksamuel.elastic4s.IndexDsl$IndexDefinitionExecutable$.apply(IndexDsl.scala:20)
at com.sksamuel.elastic4s.ElasticClient.execute(ElasticClient.scala:28)
at com.enterpriseconnector.persistence.Elastic$.insert(Elastic.scala:17)
at com.enterpriseconnector.persistence.Test$$anonfun.apply(Elastic.scala:27)
at com.enterpriseconnector.persistence.Test$$anonfun.apply(Elastic.scala:24)
at scala.collection.TraversableLike$$anonfun$map.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map.apply(TraversableLike.scala:245)
at scala.collection.immutable.Range.foreach(Range.scala:166)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at com.enterpriseconnector.persistence.Test$.delayedEndpoint$com$enterpriseconnector$persistence$Test(Elastic.scala:24)
at com.enterpriseconnector.persistence.Test$delayedInit$body.apply(Elastic.scala:23)
at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main.apply(App.scala:76)
at scala.App$$anonfun$main.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at com.enterpriseconnector.persistence.Test$.main(Elastic.scala:23)
at com.enterpriseconnector.persistence.Test.main(Elastic.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
My complete code is
我的完整代码是
import java.util.Calendar
import com.sksamuel.elastic4s.{ElasticsearchClientUri, ElasticClient}
import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.source.StringDocumentSource
import org.elasticsearch.common.settings.ImmutableSettings
object Elastic {
println("Creating Elastic Connection")
val settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch").build()
val uri = ElasticsearchClientUri("elasticsearch://192.168.99.100:9200")
val client = ElasticClient.remote(uri)
def insert(monitorJson: String) = {
client execute {
index into "test" -> "elastic4s" doc StringDocumentSource(monitorJson)
}
}
}
object Test extends App {
for (_ <- 1 to 100) yield {
val json: String = s"{time: ${Calendar.getInstance().getTime()}}"
println(s"inserting ${json}")
Elastic.insert(json)
}
}
回答by Val
9200 is the port for connecting via HTTP, which is why it works from your browser. If you check you the top of your stack trace, you can see in your case that you're connecting via the Transport client (i.e. TCP) so you need to use the port 9300 instead. Try this:
9200 是通过 HTTP 连接的端口,这就是它在您的浏览器中工作的原因。如果您检查堆栈跟踪的顶部,您可以看到您的情况是通过传输客户端(即 TCP)进行连接,因此您需要改用端口 9300。试试这个:
val uri = ElasticsearchClientUri("elasticsearch://192.168.99.100:9300")
val client = ElasticClient.remote(uri)
回答by Ashay Batwal
Make sure client version is same as ElasticSearch server.
确保客户端版本与 ElasticSearch 服务器相同。
回答by Jacek Serafinski
Try adding settigs with HTTP enabled
尝试添加启用 HTTP 的设置
Just set host:
只需设置主机:
val host = "YOUR HOST NAME"
and then:
接着:
val settings = ImmutableSettings.settingsBuilder()
.put("http.enabled", true).put("cluster.name", "CLUSTER-NAME").build()
val uri = ElasticsearchClientUri(s"${host}:9200")
val esClient = ElasticClient
.remote(settings, uri)
It should work with port 9200 now
它现在应该与端口 9200 一起使用

