elasticsearch java client

来源:互联网 发布:电脑机箱品牌知乎 编辑:程序博客网 时间:2024/04/27 04:26

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


0 0