I have an Elasticsearch cluster of 10 nodes. While connecting to the cluster via the Java API, I only connect to the master node.
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("masterNode"), 9300));
If the master node fails, will my program automatically connect to the next master node? What if I have to restart the Java program after the initial master node fails?
For TransportClient client, there is a sniff setting for client:
client.transport.sniff mode is false, the client will only try to connect the configured IPs, as:
addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("masterNode"), 9300));
client.transport.sniff mode is true, the client will firstly to connect to configured IPs, and by stats API to discover cluster available data nodes to dynamically add new hosts and remove old ones.(Notice: if your cluster with your client app has different network, there will be an issue to connect to cluster data node), as:
Settings settings = Settings.settingsBuilder() .put("client.transport.sniff", true).build(); TransportClient client = new PreBuiltTransportClient(settings);
So as your question, when sniff settings is true and they are under same network, your connected node failed, it's still can connect to cluster.
Reference: https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.0/transport-client.html