理解NodeClient、TransportClient

节点客户端,实际上是一个集群中的节点(但不保存数据,不能成为主节点)。因为它是一个节点,它知道整个集群状态(所有节点驻留,分片分布在哪些节点,等等)。 这意味着它可以执行 APIs 但少了一个网络跃点。

public class NodeClientBuild {

    protected static Node node;
    protected static Client client;

    public NodeClientBuild() {
        node = NodeBuilder
            .nodeBuilder()
            .clusterName("elasticsearch")
            .settings(Settings
                .builder()
                .put("path.home", "./target/es")
                .put("node.name", "test_node"))
            .client(true)
            .node();

        client = node.client();
    }

    public static void main(String[] args) throws InterruptedException {
        NodeClientBuild build = new NodeClientBuild();

        TimeUnit.SECONDS.sleep(100000);
    }

}

启动之前本地已经运行了一个ES节点,启动过程中会自动分配一个合理的端口,可以看出策略是自动加1。


启动日志
启动节点

节点启动后,会自动加入集群,从attributes中可以看出,这仅仅是个client,不会存储数据。

集群信息

https://endymecy.gitbooks.io/elasticsearch-guide-chinese/content/java-api/client.html

https://www.elastic.co/guide/cn/elasticsearch/guide/current/_transport_client_versus_node_client.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容