zoukankan      html  css  js  c++  java
  • (26)ElasticSearch java项目中获取集群、索引信息

      下面的代码展示了如何获取集群信息和索引信息

    @Test
        public void testCluster() throws IOException, InterruptedException, ExecutionException {
            //指定集群
            Settings settings = Settings.builder().put("cluster.name","my-application").build(); 
            //创建客户端
            TransportClient client = new PreBuiltTransportClient(settings)
                                    .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.43.151"),9300));
            ClusterHealthResponse healths = client.admin().cluster().prepareHealth().get();
            String clusterName = healths.getClusterName();
            //输出集群名
            System.out.println("clusterName = :"+clusterName);
            int numberOfDataNodes = healths.getNumberOfDataNodes();
            //输出节点数量
            System.out.println("numberOfDataNodes = :"+numberOfDataNodes);
            //输出每个索引信息
            for(ClusterIndexHealth health:healths.getIndices().values()) {
                String index = health.getIndex();
                int numberOfShards = health.getNumberOfShards();
                int numberOfReplicas = health.getNumberOfReplicas();
                System.out.println("index = "+index);//索引名
                System.out.println("numberOfShards = "+numberOfShards);//分片数量
                System.out.println("numberOfReplicas = "+numberOfReplicas);//副本数量
                
                ClusterHealthStatus clusterHealthStatus = health.getStatus();
                System.out.println("clusterHealthStatus = "+clusterHealthStatus.toString());//健康状态
            }
            client.close();
       }
  • 相关阅读:
    python列表
    OSS对象存储的文件上传、解冻、下载与查看
    常用压缩命令
    SWAP
    K8S_第一课作业_20200407
    K8S--- yaml配置文件
    K8S 简介
    php-fpm进程数控制
    linux常用查询命令
    Docker Note1——架构和三要素
  • 原文地址:https://www.cnblogs.com/javasl/p/12081829.html
Copyright © 2011-2022 走看看