use of org.elasticsearch.client.transport.TransportClient in project play2-elasticsearch by cleverage.
the class IndexClient method start.
public void start() throws Exception {
// Load Elasticsearch Settings
Settings.Builder settings = loadSettings();
// Check Model
if (this.isLocalMode()) {
Logger.info("ElasticSearch : Starting in Local Mode");
NodeBuilder nb = nodeBuilder().settings(settings).local(true).client(false).data(true);
node = nb.node();
client = node.client();
Logger.info("ElasticSearch : Started in Local Mode");
} else {
Logger.info("ElasticSearch : Starting in Client Mode");
TransportClient c = TransportClient.builder().settings(settings).build();
if (config.client == null) {
throw new Exception("Configuration required - elasticsearch.client when local model is disabled!");
}
String[] hosts = config.client.trim().split(",");
boolean done = false;
for (String host : hosts) {
String[] parts = host.split(":");
if (parts.length != 2) {
throw new Exception("Invalid Host: " + host);
}
Logger.info("ElasticSearch : Client - Host: " + parts[0] + " Port: " + parts[1]);
c.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(parts[0]), Integer.valueOf(parts[1])));
done = true;
}
if (!done) {
throw new Exception("No Hosts Provided for ElasticSearch!");
}
client = c;
Logger.info("ElasticSearch : Started in Client Mode");
}
// Check Client
if (client == null) {
throw new Exception("ElasticSearch Client cannot be null - please check the configuration provided and the health of your ElasticSearch instances.");
}
}
Aggregations