简体   繁体   中英

NoNodeAvailableException : None of the configured nodes are available

I'm trying to search from Elastic Search within my Java Web Service, here's how I use now :

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

No matter I use 9200 or 9300 to set the port , the results are the same.

Also, I've tried to search from my .Net program using NEST , and it run just fine. Here's how I tried :

    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 , version of library, method to call the API, etc) wrong with my Java program? My current Java version is 1.8.0.121 , the version of Elastic Search and Transport Client are both 5.2 . Thanks!

As discussed in comments,

If you are using a cluster name other than elasticsearch , then you need to update the same in settings.

Settings settings = Settings.builder()
        .put("cluster.name", "myClusterName").build();

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.

Here is solutions - https://www.elastic.co/guide/en/x-pack/current/java-clients.html

From documentation,

// on startup

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

If you are install elasticsearch from extracted file (eg: 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.html It help me solve this problem.

Before executing the program make sure you ran the elasticSearch.bat batch file present under ElasticSearch -> config folder . Also make sure you see "started" logged in the console where you ran the batch file.

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:

{
  "name" : ...,
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : ...,
  "version" : {
    "number" : "5.5.2",
    ...
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}

Add the cluster name as a parameter on the connection URI:

  1. Go to http://<elasticsearch_host>:9200
  2. Retrieve the cluster_name value and add it as a parameter to the connection URI: elasticsearch://<elasticsearch_host>:9300?cluster.name=<cluster_name_value>

This Exception is pointing to elasticSearch transport client is not able to establish a connection with elasticsearch server.

Root cause might be the port name or IP/hostname of server OR cluster Name OR Authentication is incorrect.

Open elasticSearch.yaml file and validate all details correctly. To ignore clusterName validation by using the following configuration params.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM