Java中怎么利用elasticsearch實現(xiàn)集群管理功能,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
@Testpublic 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);//健康-綠色 一般-黃色 不健康-紅色 }}
關(guān)于Java中怎么利用elasticsearch實現(xiàn)集群管理功能問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。
分享標題:Java中怎么利用elasticsearch實現(xiàn)集群管理功能-創(chuàng)新互聯(lián)
標題鏈接:http://chinadenli.net/article36/cdjisg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供Google、軟件開發(fā)、網(wǎng)站收錄、自適應網(wǎng)站、網(wǎng)站策劃、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容