2015-11-04 27 views
1

[使用ElasticSearch版本2.0]ElasticSearch 2.0傳送客戶 - 無節點可用的例外

在etc/hosts文件 「esnode」 被映射到IP地址,如圖(其中ES運行一些其它機器)

192.168.2.219 esnode

的傳輸客戶端代碼::

public Client getClient() { 
    if ((this.client == null)) { 
     try { 
      Settings settings = Settings.settingsBuilder() 
        .put("cluster.name", "myclustername").build(); 
      TransportClient tClient = TransportClient.builder().settings(settings).build(); 
      String[] nodes = "esnode:9300".split(COMMA); 
      for (String node : nodes) { 
       String[] hostPort = node.split(COLON); 

       tClient.addTransportAddress(new InetSocketTransportAddress( 
         InetAddress.getByName(hostPort[0]), Integer.parseInt(hostPort[1]))); 
      } 
      this.client = tClient; 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
    return this.client; 
} 

該客戶端代碼運行,但執行下面的代碼時: this.getClient()。prepareGet(indexName,typeName,String.valueOf(id))。get();

拋出異常:

NoNodeAvailableException[None of the configured nodes are available: []] 
     at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:280) 
     at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:197) 
     at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55) 
     at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:272) 
     at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:347) 
     at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:85) 
     at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:59) 
     at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:67) 

我也用,而不是主機名ip地址嘗試。上面的代碼運行正常,如果

esnode被映射到127.0.0.1

有人可以幫...

+0

你讀過[這個答案](http://stackoverflow.com/a/23521094/3219121)? – matagus

回答

0

檢查您elasticsearch服務器也有2.0的版本,如果沒有,升級。客戶端和服務器必須具有相同的版本才能工作,我不知道爲什麼,但這解決了我的問題。

乾杯,

+0

客戶端和服務器版本相同,適用於127.0.0.1。但不適用於任何其他IP地址(網絡中可用的ES節點)。 – sanesearch

+0

ES配置有問題。 使用後續配置: **羣集。名稱:esearch ** ** http.port:9200 ** 只有以上兩個屬性在config中明確設置。休息時使用默認值。 – sanesearch

1

設置elasticsearch主機IP地址network.host值elasticsearch.yml

network.host:es_host_ip

這是解決TransportClient NoNodeAvailableException問題。

0

其他原因可能是,你Elasticsearch Java客戶端是從Elasticsearch服務器不同的版本。

Elasticsearch Java客戶端版本不過是您的代碼庫中的彈性搜索jar版本。

例如:在我的代碼是elasticsearch-2.4.0.jar

要驗證Elasticsearch服務器版本,

$ /用戶/ kkolipaka/elasticsearch /斌/ elasticsearch -version版本: 5.2.2建築:f9d9b74/2017-02-24T17:26:45.835Z,JVM:1.8.0_111

正如你所看到的,我已經下載了最新版本的彈性服務器5.2.2,但對於有更新的ES Java API客戶端版本2.4.0 https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html

相關問題