The following code shows how to get the cluster information and index information
@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(); ClusterName String = healths.getClusterName (); // output cluster name System.out.println ( "clusterName =:" + clusterName); int numberOfDataNodes = healths.getNumberOfDataNodes (); // output node number System.out.println ( " = numberOfDataNodes: "+ numberOfDataNodes); // output of each index information 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 ()); // health } client.close(); }