Getting org.elasticsearch.transport.NodeDisconnectedException: [][inet[localhost/127.0.0.1:9300]][cluster/nodes/info] disconnected

匿名 (未验证) 提交于 2019-12-03 09:52:54

问题:

I am New in Elastic Search Java Api[5.0]. I am Using elasticsearch-5.0.0. I am try to create a Java Application(Maven) with Spring Boot. After run Application, it shows

2016-11-04 23:32:19.339  INFO 8280 --- [][generic][T#2]]      org.elasticsearch.client.transport       : [X-Ray] failed to get node info for [#transport#-1][DESKTOP-8SIPHSN][inet[localhost/127.0.0.1:9300]], disconnecting... org.elasticsearch.transport.NodeDisconnectedException: [][inet[localhost/127.0.0.1:9300]][cluster:monitor/nodes/info] disconnected  

My Config File Is

@Configuration public class ElasticsearchConfiguration {    @Bean   public Client client() {          TransportClient client = new TransportClient();         TransportAddress address = new  InetSocketTransportAddress("localhost",9300);         client.addTransportAddress(address);                 return client;     }  } 

And I am using default cluster "elasticsearch". I need help to solve my issue with proper detection of causes.

回答1:

Try using the PreBuiltTransportClient mentioned in the 5.0 documentation:

TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)         .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300)); 

https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html

Also note that the TransportClient for ES version 2.x isn't compatible with 5.x:

The client must have the same major version (e.g. 2.x, or 5.x) as the nodes in the cluster. Clients may connect to clusters which have a different minor version (e.g. 2.3.x) but it is possible that new functionality may not be supported. Ideally, the client should have the same version as the cluster.

https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html

Update

As a connectivity test, try executing the following simple program:

import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.transport.client.PreBuiltTransportClient;  import java.net.InetAddress; import java.net.UnknownHostException;  public class App {     public static void main(String[] args) throws UnknownHostException {         // The following settings aren't strictly necessary, because the default cluster name is "elasticsearch".         Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();         TransportClient client = new PreBuiltTransportClient(settings);         client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));         System.out.println(client.connectedNodes());     } } 

It should print to stdout something like the following line:

[{luhcORJ}{luhcORJOSzSLPBeXocDsuQ}{mkTJpwIAQGuNYTHfRLqUIw}{127.0.0.1}{127.0.0.1:9300}]



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!