elasticsearch 6.x.x 获取客户端方法
创建Settings
Settings settings = Settings.builder().put("client.transport.ignore_cluster_name", true).build();//忽略集群名称
创建客户端
TransportClient transportClient = new PreBuiltTransportClient(settings);
获取客户端
Client client = transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName(host), Integer.parseInt(port)));
// 创建客户端
Settings settings = Settings.builder().put("cluster.name", "clustername").put("client.transport.sniff", true).build();//根据集群名称创建setting
TransportClient client = new PreBuiltTransportClient(settings);
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("IP"), 9300));
以上为两种获取es不同setting的方式,指定集群名称获取集群,或者不指定集群名称获取集群。