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

10,240

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}]

Share:
10,240
Md Hafezur Rahman
Author by

Md Hafezur Rahman

Updated on June 15, 2022

Comments

  • Md Hafezur Rahman
    Md Hafezur Rahman almost 2 years

    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.

  • Md Hafezur Rahman
    Md Hafezur Rahman over 7 years
    i am using <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>transport</artifactId> <version>5.0.0</version> </dependency>
  • Md Hafezur Rahman
    Md Hafezur Rahman over 7 years
    I am Trying to this code TransportClient client = new PreBuiltTransportClient(Settings.EMPTY) .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"‌​), 9300)); but Settings.EMPTY showing Error
  • ck1
    ck1 over 7 years
    Did you rename your cluster? If it's something other than elasticsearch, you need to specify that in the cluster.name property in the TransportClient settings.
  • Md Hafezur Rahman
    Md Hafezur Rahman over 7 years
    I can't Specify why, Showing Settings.EMPTY error, I am Trying both default cluster name and rename cluster. When I rename cluster name, and set it Settings settings = Settings.builder().put("cluster.name", "geo-location").build(); TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); Then it shows Settings.builder() as error. Here i am using this package import org.elasticsearch.common.settings.Settings;
  • Md Hafezur Rahman
    Md Hafezur Rahman over 7 years
    Hello @ck1 can you explain me why i am get error Settings settings = Settings.builder().put("cluster.name", "geo-location").build(); ?
  • ck1
    ck1 over 7 years
    I've updated my test program above to create a Settings instance. If this doesn't work for you, can you paste the specific exception that you're seeing?
  • Md Hafezur Rahman
    Md Hafezur Rahman over 7 years
    @Configuration public class ElasticsearchConfiguration { @Bean public Client client() throws UnknownHostException { Settings settings = Settings.builder().put("cluster.name", "geo-location").build(); TransportClient client = new PreBuiltTransportClient(settings). addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"‌​), 9300)); return client; } }
  • Md Hafezur Rahman
    Md Hafezur Rahman over 7 years
    Information:11/5/2016 9:55 AM - Compilation completed with 1 error and 0 warnings in 12s 217ms E:\ElasticSearchProject\GeoSearch\src\main\java\com\location‌​\configuration\Elast‌​icsearchConfiguratio‌​n.java Error:(25, 37) java: cannot find symbol symbol: method builder() location: interface org.elasticsearch.common.settings.Settings Information:java: E:\ElasticSearchProject\GeoSearch\src\main\java\com\location‌​\configuration\Elast‌​icsearchConfiguratio‌​n.java uses unchecked or unsafe operations. Information:java: Recompile with -Xlint:unchecked for details.
  • Md Hafezur Rahman
    Md Hafezur Rahman over 7 years
    Thanks @ck1,Finally it works. But can't define my problem what was. I just recreate a project and paste your update code.