Elasticsearch版本客户端与服务端版本不一致问题

高版本的客户端不能调用低版本的服务端。

异常:org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available

出现以上异常原因:

1、端口或IP或集群名称设置错误

2、客户端版本与服务器版本不一致

elasticsearch2.X调用方式

 public static Client getClient() throws UnknownHostException {
    	String clusterName = "elasticsearch";
    	List<String> clusterNodes = Arrays.asList("http://172.16.0.29:9300");
    	Settings settings = Settings.settingsBuilder().put("cluster.name", clusterName).build();  
    	TransportClient client = TransportClient.builder().settings(settings).build();
        for (String node : clusterNodes) {
            URI host = URI.create(node);
        	client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host.getHost()), host.getPort()));
        }
        return client;
    }
elasticsearch5.X调用方式

public static Client getClient() throws UnknownHostException {
    	String clusterName = "shopmall-es";
    	List<String> clusterNodes = Arrays.asList("http://172.16.32.69:9300","http://172.16.32.48:9300");
        Settings settings = Settings.builder().put("cluster.name", clusterName).build();
        TransportClient client = new PreBuiltTransportClient(settings);
        for (String node : clusterNodes) {
            URI host = URI.create(node);
            client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host.getHost()), host.getPort()));
        }
        return client;
    }




版权声明:本文为wwd0501原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。