elasticsearch java api 提供两个客户端类Node Client ,TransportClient
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html
Node node = nodeBuilder().clusterName("yourclustername").node();
Client client = node.client();
Node Client:
1.本身也是集群节点之一。
// on startupClient
client=TransportClient.builder().build().addTransportAddress(newInetSocketTransportAddress(InetAddress.getByName("host1"),9300)).addTransportAddress(newInetSocketTransportAddress(InetAddress.getByName("host2"),9300));
// on shutdownclient.close();
TransportClient
1.客户端不需要是集群中节点。
2.可以连接多个集群中节点。
3.设置client.transport.sniff为true来使客户端去嗅探整个集群的状态,把集群中其它机器的ip地址加到客户端中