这里是我的Service实现类, Controller 和 DAO层省略。
public void insertBigData() {
//如果使用默认的cluster请保持Setting Empty
Settings settings = Settings.EMPTY;
TransportClient client;
try {
//TransportClient连接es
client = createConnection(settings,"127.0.0.1",9300);
//调用插入大量数据方法
String message = insertSomeRecords(client);
System.out.println(message);
//关闭连接
client.close();
}catch(Exception e){
e.printStackTrace();
}
return result;
}
建立TransportClient连接的方法
private TransportClient createConnection(Settings settings,String ip,int port) throws UnknownHostException{
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTr