Kidong Lee
1 min readMar 14, 2019

--

You can instantiate TransportClient in java like this:

// elasticsearch nodes.
String esServers = "es1:9300,es2:9300";
String[] tokens = esServers.split(",");

Map<String, Integer> hostPortMap = new HashMap<>();

for (String token : tokens) {
String[] hostPort = token.split(":");
hostPortMap.put(hostPort[0], Integer.parseInt(hostPort[1]));
}

// elastic search setting.
Settings settings = Settings.builder()
.put("cluster.name", "my-cluster")
.put("client.transport.sniff", true)
.build();

// elastic search client.
TransportClient client = new PreBuiltTransportClient(settings);

for (String host : hostPortMap.keySet()) {
log.info("es host: " + host);
client.addTransportAddress(new TransportAddress(InetAddress.getByName(host), hostPortMap.get(host)));
}

--

--

Kidong Lee
Kidong Lee

Written by Kidong Lee

Founder of Cloud Chef Labs | Chango | Unified Data Lakehouse Platform | Iceberg centric Data Lakehouses https://www.cloudchef-labs.com/

No responses yet