NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{9L7K2EanQGSxD5aAmbzAIw}{localhost}{127.0.0.1:9200}]]
这里显示无可用节点异常,找了相关的博客,把elasticsearch.yaml文件中的cluster.name: my-application取消注释,并且在创建TransportClient时也设置了,原来设置为空;
Settings settings = Settings.builder().put("cluster.name","my-application") .put("client.transport.sniff", true) .build(); TransportClient transportClient = new PreBuiltTransportClient(settings) .addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), Integer.valueOf(9200)));
一步步Debug这里仍然报错;
由于前面也使用了
RestHighLevelClient
RestHighLevelClient restHighLevelClient = new RestHighLevelClient( RestClient.builder(new HttpHost("localhost", 9200, "http")) );
感觉有可能是端口的问题,把端口改为9300
Settings settings = Settings.builder().put("cluster.name","my-application") .put("client.transport.sniff", true) .build(); TransportClient transportClient = new PreBuiltTransportClient(settings) .addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), Integer.valueOf(9300)));
重新运行,没有报错;
尝试在elasticsearch.yaml文件注释掉cluster.name,并且初始化时my-application也为空,重新运行,仍然没有报错!
Settings settings = Settings.builder().put("cluster.name","") .put("client.transport.sniff", true) .build(); TransportClient transportClient = new PreBuiltTransportClient(settings) .addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), Integer.valueOf(9300)));
标签:available,None,Settings,configured,settings,cluster,put,new,localhost From: https://www.cnblogs.com/litchihan/p/16731099.html