Skip to content

Instantly share code, notes, and snippets.

Created May 9, 2011 18:46
Show Gist options
  • Save anonymous/963103 to your computer and use it in GitHub Desktop.
Save anonymous/963103 to your computer and use it in GitHub Desktop.
elasticSearch_transport
private void initializeClient() throws Exception {
// add transport addresses
client = new TransportClient(ImmutableSettings.settingsBuilder()
.put("cluster.name", "elasticsearch") // currently hardcoded
.put("client.transport.sniff", true));
for (String server : servers) {
URL indexUrl = new URL(server);
String host = indexUrl.getHost();
Integer port = new Integer(indexUrl.getPort());
index = indexUrl.getPath().substring(1).split("/")[0];
type = indexUrl.getPath().substring(1).split("/")[1];
LOG.info("host:" + host);
LOG.info("port:" + port);
LOG.info("index:" + index);
LOG.info("type:" + type);
client.addTransportAddress(new InetSocketTransportAddress(host, port));
}
int retry = 0;
while (client.connectedNodes().isEmpty()) {
retry++;
LOG.info("waiting for nodes to connect attempt " + retry);
Thread.sleep(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment