java NoNodeAvailableException : 没有配置的节点可用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42826735/
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
NoNodeAvailableException : None of the configured nodes are available
提问by Alanight
I'm trying to search from Elastic Search within my Java Web Service, here's how I use now :
我正在尝试从我的 Java Web 服务中的 Elastic Search 进行搜索,这是我现在的使用方式:
Client client = new PreBuiltTransportClient(Settings.EMPTY).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.10.150"), 9200));
SearchResponse searchResponse = client.prepareSearch().execute().actionGet();
The 1st line could work without an error, but when it goes to the 2nd line, the exception down below will occur :
第一行可以正常工作,但当它转到第二行时,将发生下面的异常:
NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{TskPSVeBRR6CvCzP9EVhkQ}{192.168.10.150}{192.168.10.150:9200}]]
NoNodeAvailableException[没有配置的节点可用:[{#transport#-1}{TskPSVeBRR6CvCzP9EVhkQ}{192.168.10.150}{192.168.10.150:9200}]]
No matter I use 9200or 9300to set the port, the results are the same.
不管我用9200还是9300设置端口,结果都是一样的。
Also, I've tried to search from my .Netprogram using NEST, and it run just fine. Here's how I tried :
另外,我尝试使用NEST从我的.Net程序中进行搜索,并且它运行得很好。这是我尝试的方法:
var node = new Uri("http://192.168.10.150:9200");
var settings = new ConnectionSettings(node).DefaultIndex("iod-2017.03.08.*");
_EsClient = new ElasticClient(settings);
var index = String.Format("iod-{0}.{1:00}.{2:00}.*", item.TriggerTime.Year, item.TriggerTime.Month, item.TriggerTime.Day);
var uniqueId = item.UniqueId.ToString();
var result = _EsClient.Search<logs>(s => s.Index(index).Query(q => q.Match(t => t.Field(l => l.id).Query(uniqueId))));
Did I do anything(Firewall, versionof library, methodto call the API, etc) wrong with my Java program? My current Javaversion is 1.8.0.121, the version of Elastic Searchand Transport Clientare both 5.2. Thanks!
我的 Java 程序有没有做错什么(防火墙、库版本、调用 API 的方法等)?我当前的Java版本是1.8.0.121,Elastic Search和Transport Client的版本都是5.2。谢谢!
回答by Rahul
As discussed in comments,
正如评论中所讨论的,
If you are you using a cluster name other than elasticsearch, then you need to update the same in settings.
如果您使用的集群名称不是 elasticsearch,那么您需要在设置中更新相同的名称。
Settings settings = Settings.builder()
.put("cluster.name", "myClusterName").build();
回答by CR Sardar
I was facing the same issue, my cluster name & everything were correct, but my elastic cluster was using X-Pack Security. And it was only because of that.
我遇到了同样的问题,我的集群名称和一切都是正确的,但我的弹性集群使用的是 X-Pack Security。也正因为如此。
Here is solutions - https://www.elastic.co/guide/en/x-pack/current/java-clients.html
这是解决方案 - https://www.elastic.co/guide/en/x-pack/current/java-clients.html
回答by Mini
Before executing the program make sure you ran the elasticSearch.batbatch file present under ElasticSearch -> config folder. Also make sure you see "started"logged in the console where you ran the batch file.
在执行程序之前,请确保您运行了ElasticSearch -> config folder下的elasticSearch.bat批处理文件。还要确保在运行批处理文件的控制台中看到“已启动”记录。
You can check if elastic search started successfully or not by hitting the URL localhost:9200. You should see a page looking something like this:
您可以通过点击 URL localhost:9200来检查弹性搜索是否成功启动。你应该看到一个看起来像这样的页面:
{
"name" : ...,
"cluster_name" : "elasticsearch",
"cluster_uuid" : ...,
"version" : {
"number" : "5.5.2",
...
"build_snapshot" : false,
"lucene_version" : "6.6.0"
},
"tagline" : "You Know, for Search"
}
回答by Joel Mata
Add the cluster name as a parameter on the connection URI:
在连接 URI 上添加集群名称作为参数:
- Go to
http://<elasticsearch_host>:9200
- Retrieve the
cluster_name
value and add it as a parameter to the connection URI:elasticsearch://<elasticsearch_host>:9300?cluster.name=<cluster_name_value>
- 去
http://<elasticsearch_host>:9200
- 检索该
cluster_name
值并将其作为参数添加到连接 URI 中:elasticsearch://<elasticsearch_host>:9300?cluster.name=<cluster_name_value>
回答by Rajeev Rathor
This Exception is pointing to elasticSearch transport client is not able to establish a connection with elasticsearch server.
此异常指向 elasticSearch 传输客户端无法与 elasticsearch 服务器建立连接。
Root cause might be the port name or IP/hostname of server OR cluster Name OR Authenticationis incorrect.
根本原因可能是服务器的端口名称或 IP/主机名或集群名称或身份验证不正确。
Open elasticSearch.yaml file and validate all details correctly. To ignore clusterName validation by using the following configuration params.
打开 elasticSearch.yaml 文件并正确验证所有详细信息。使用以下配置参数忽略 clusterName 验证。
client.transport.ignore_cluster_name = true
Full code snippet to create transport Client is:
创建传输客户端的完整代码片段是:
Settings settingsBuilder = Settings.builder()
.put("cluster.name", DBPropertyUtil.getPropertyByName("es.cluster")).put("client.transport.sniff", true).put("client.transport.ignore_cluster_name", true).build();
//.put("client.transport.sniff", true).put("path.home", ".").build();
Client client = new PreBuiltTransportClient(settingsBuilder)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));
Specify host and port as per your server. This code is working fine for me.
根据您的服务器指定主机和端口。这段代码对我来说很好用。
回答by Praveen
From documentation,
从文档来看,
// on startup
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));
回答by user3804997
If you are install elasticsearch from extracted file (e.g.: elasticsearch-5.4.0.tar.gz), please try to install it in through yum or other RPM tool. https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.htmlIt help me solve this problem.
如果您是从解压文件中安装elasticsearch(例如:elasticsearch-5.4.0.tar.gz),请尝试通过yum 或其他RPM 工具安装。https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html它帮助我解决了这个问题。