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();
       }
  • 相关阅读:
    VMware 创建的虚拟机,Xshell无法进行连接
    Centos7 文件修改详情
    Centos7 selinux关闭
    centos7 RPM命令使用
    centos 操作系统优化
    centos 内存使用情况+负载使用情况
    Centos 修改环境变量
    centos7 系统级别(持续更新)
    centos7 常规修改信息(比较杂的)持续更新
    centos7 修改网卡信息
  • 原文地址:https://www.cnblogs.com/javasl/p/12081829.html
Copyright © 2011-2022 走看看