2016-04-26 69 views
0

我在嘗試連接到我的ES羣集的最基本情況,但似乎我註冊的主機沒有被註冊。這是我運行代碼:ElasticSearch(java) - 未配置節點問題

//Create the client 
Client client = new TransportClient(ImmutableSettings.builder() 
    .put("cluster.name", "MyCluster") 
    .put("client.transport.sniff","true").build()) 
    .addTransportAddresses(
     new InetSocketTransportAddress("host1", 9300), 
     new InetSocketTransportAddress("host2", 9300)); 

// Try to make a call 
SearchRequest sr = new SearchRequest().indices("MyIndex"); 
ActionFuture<SearchResponse> search = client.search(sr); 
SearchResponse actionGet = search.actionGet(); // <-- Exception 
System.out.println(actionGet.toString()); 

client.close(); 

這是例外,我得到:在線程「主要」 org.elasticsearch.client.transport.NoNodeAvailableException

例外:
無配置的節點可用:[]

它看起來像沒有連接的節點,我錯過了什麼?

注:我使用的是彈性的搜索客戶端gradle這個:
編譯 'org.elasticsearch:elasticsearch:1.7.5'

+0

你的集羣是否正常工作?您客戶端和服務器的版本是否相同/兼容? – alpert

+1

羣集與REST調用正常工作。我認爲我有相同的版本,我如何檢查服務器上的版本? –

+0

只需鍵入'curl -XGET'http:// host:9200'。同時檢查羣集名稱。 – alpert

回答

2

這有一些可能的原因:

  • 客戶端和服務器版本可能不同
  • 集羣名稱可能不同
  • 訪問h時可能會出現網絡問題ost和端口。