use of org.elasticsearch.transport.client.PreBuiltTransportClient in project springboot_op by SnailFastGo.
the class ElasticsearchConfiguration method initESClient.
@Bean
public TransportClient initESClient() throws NumberFormatException, UnknownHostException {
String ip = env.getProperty("spring.es.ip");
String port = env.getProperty("spring.es.port");
String clusterName = env.getProperty("spring.es.cluster_name");
Builder builder = Settings.builder().put("cluster.name", clusterName).put("client.transport.sniff", true);
Settings esSettings = builder.build();
TransportClient client = new PreBuiltTransportClient(esSettings);
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), Integer.parseInt(port)));
logger.info("ES Client 初始化成功, ip : {}, port : {}, cluster_name : {}", ip, port, clusterName);
return client;
}
Aggregations