elasticsearch java client

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地址加到客戶端中


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章