您好,登錄后才能下訂單哦!
這篇文章主要介紹了java基于elasticsearch實現(xiàn)集群管理,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
本篇文章主要是查看集群中的相關信息,具體請看代碼和注釋
@Test public void test45() throws UnknownHostException{ //1、指定es集群 cluster.name 是固定的key值,my-application是ES集群的名稱 Settings settings = Settings.builder().put("cluster.name", "my-application").build(); //2.創(chuàng)建訪問ES服務器的客戶端 TransportClient client = new PreBuiltTransportClient(settings) .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.1.94"), 9300)); //獲取集群信息 ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().get(); //獲取集群名稱 String clusterName = healthResponse.getClusterName(); System.out.println(clusterName); //獲取存放數(shù)據(jù)的那些節(jié)點 int numberOfDataNodes = healthResponse.getNumberOfDataNodes(); System.out.println(numberOfDataNodes); //獲取節(jié)點的總數(shù)量 int numberOfNodes = healthResponse.getNumberOfNodes(); System.out.println(numberOfNodes); //獲取集群中一共有多少索引 for(ClusterIndexHealth health:healthResponse.getIndices().values()) { String index = health.getIndex();//當前索引名稱 int numberOfShards = health.getNumberOfShards();//主分片 int numberOfReplicas = health.getNumberOfReplicas();//副本 ClusterHealthStatus status = health.getStatus();//得到當前的健康狀況 System.out.println(status);//健康-綠色 一般-黃色 不健康-紅色 } }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。