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();
       }
  • 相关阅读:
    文件操作
    匿名函数
    函数
    运算符
    (模板)扩展kmp算法(luoguP5410)
    poj2406(求字符串的周期,kmp算法next数组的应用)
    poj1961(kmp算法next数组应用)
    hdoj1711(kmp算法)
    (模板)poj3461(kmp模板题)
    fzu1704(高斯消元法解异或方程组+高精度输出)
  • 原文地址:https://www.cnblogs.com/javasl/p/12081829.html
Copyright © 2011-2022 走看看