ElasticSearch学习(7)-Java连接ElasticSearch集群

原创
2018/01/31 09:14
阅读数 1.2W

Java 操作ElasticSearch集群非常简单,和操作单个节点一样,只是连接方式不同

Java连接ElasticSearch集群只需要主节点的ip和端口号,然后配置集群的名字即可。

    private static final String host = "192.168.15.38";

    private static final int port = 9300;
    private static TransportClient client = null;

    private static final String CLUSTER_NAME = "my-application";

    private static Settings.Builder builder = Settings.builder().put("cluster.name", CLUSTER_NAME);

    public static TransportClient cilentFactory() {
        client = new PreBuiltTransportClient(builder.build()).addTransportAddress(new TransportAddress(new InetSocketAddress(host, port)));
        return client;
    }

    public static void close() {
        if (client != null) {
            client.close();
        }
    }
展开阅读全文
加载中

作者的其它热门文章

打赏
0
2 收藏
分享
打赏
3 评论
2 收藏
0
分享
返回顶部
顶部
返回顶部
顶部