2016-09-12 70 views
6
Settings settings = Settings.settingsBuilder() 
       .put("cluster.name", "logging_elasticsearch") 
       .build(); 
     TransportClient client = TransportClient.builder() 
       .settings(settings) 
       .build() 
       .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByAddress(new byte[]{10,100,30,62}), 9300)); 

    SearchResponse response = client.prepareSearch("logstash-2016.09.08") 
      .setTypes("type1", "type2") 
      .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 
      .setQuery(QueryBuilders.termQuery("multi", "test"))     // Query 
      .setPostFilter(QueryBuilders.rangeQuery("age").from(12).to(18))  // Filter 
      .setFrom(0).setSize(60).setExplain(true) 
      .execute() 
      .actionGet(); 

elasticsearch.yml 執行我的搜索查詢時,我得到一個NoNodeAvailableException配置的節點Elasticsearch NoNodeAvailableException無可用

我試過這個解決方案: https://stackoverflow.com/a/33875764/2616923 但它沒有工作。

回答

0

試試這個方法,你的代碼似乎是相當接近:

Settings settings = Settings.settingsBuilder() 
     .put("cluster.name", "<elasticsearch-cluster-name>") 
     .build(); 

Client client = new TransportClient.Builder() 
      .settings(settings) 
      .build() 
      .addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("<elasticsearch-network-host>", <elasticsearch-transport-client-port|default 9300>))); 

==== elasticsearch.yml ====

cluster.name: <elasticsearch-cluster-name> 
node.name: <elasticsearch-network-host> 
network.host: <elasticsearch-network-host> 
network.bind_host: 0 
0

嘗試將設置與節點名稱下面一樣,

Settings esSettings = Settings.builder().put("cluster.name", esClusterName) 
.put("node.name",esNodeName) 
0
I have created transport client with more parameters. Below code is perfectly running in production. 

    Settings settingsBuilder = Settings.builder() 
      .put("cluster.name", DBPropertyUtil.getPropertyByName("es.cluster")).put("client.transport.sniff", true).put("client.transport.ignore_cluster_name", true).build(); 

     Client client = new PreBuiltTransportClient(settingsBuilder) 
      .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port)); 

Put respective details for host, port, clusterName as per your elasticSearch Servers config. 
相關問題