ElasticSearch java客戶端更新時出現的錯誤:NoNodeAvailableException[None of the configured nodes are available


下午嘗試 用ElasticSearch  的java客戶端去做數據檢索工作,測試了一下批量更新,代碼如下:

public static void bulkUpdateGoods(List<Goods> goods) throws IOException, InterruptedException, ExecutionException {
        Client client = null;
        try {
            client = TransportClient.builder().build()
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("hadoop-slave4"), 9300));
            
        } catch (Exception e) {
            e.printStackTrace();
        }

        BulkRequestBuilder req = client.prepareBulk();

        for (Goods good : goods) {
            req.add(client.prepareIndex("smms", "goods", good.getId() + "")
                    .setSource(jsonBuilder().startObject().field("unit", good.getUnit()).field("price", good.getPrice())
                            .field("name", good.getName()).field("barcode", good.getBarCode()).endObject()));
        }

        BulkResponse res = req.execute().actionGet();

        if (res.hasFailures()) {
            System.out.println("Error");
        } else {
            System.out.println("Done");
        }

        client.close();
    }
}

 

但是測試的時候老是給我報這個錯誤:NoNodeAvailableException[None of the configured nodes are available。具體沒截圖。

然后我改正兩點后解決問題,一處是用9300端口 而不是9200.9200端口只是HTTP端口。

第二處是我把配置文件里cluter.name給注釋掉了,就能用了。具體原理不清楚。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM