public ESDriver(String clusterName){
node =
nodeBuilder()
.settings(ImmutableSettings.settingsBuilder().put("http.enabled", false))
.clusterName(clusterName)
.client(true)
.node();
client = node.client();
}
public ESDriver(Map<String, String> config){
Settings settings = System.getProperty("file.separator").equals("/") ? ImmutableSettings.settingsBuilder()
.put("http.enabled", "false")
.put("transport.tcp.port", config.get("ES_Transport_TCP_Port"))
.put("discovery.zen.ping.multicast.enabled", "false")
.put("discovery.zen.ping.unicast.hosts", config.get("ES_unicast_hosts"))
.build() : ImmutableSettings.settingsBuilder()
.put("http.enabled", false)
.build();;
node =
nodeBuilder()
.settings(settings)
.clusterName(config.get("clusterName"))
.client(true)
.node();
client = node.client();
}
This is not the preferred way to interact with an existing Elasticsearch cluster and we should use the more efficient TransportClient instead.
// Prefer TransportClient
if (hosts != null && port > 1) {
TransportClient transportClient = TransportClient.builder().settings(settings).build();
for (String host: hosts)
transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));
client = transportClient;
} else if (clusterName != null) {
node = nodeBuilder().settings(settings).client(true).node();
client = node.client();
}
This will significantly improve the performance of Mudrod initiation.