动态创建连接,数组里可以存放elasticsearch服务的ip地址
Client client = null;
try {
String[] urllist = URL.split(",");
List<InetSocketTransportAddress> list = new ArrayList<InetSocketTransportAddress>();
for(String str : urllist){
logger.info(str);
InetSocketTransportAddress transportAddress = new InetSocketTransportAddress(InetAddress.getByName(str),9300);
list.add(transportAddress);
}
logger.info("创建Elasticsearch Client 开始");
client = TransportClient.builder().build()
.addTransportAddresses(list.toArray(new InetSocketTransportAddress[list.size()]));
logger.info("创建Elasticsearch Client 结束");
} catch (Exception e) {
logger.error("创建Elasticsearch Client 异常"+URL);
}