這篇文章主要介紹了java基于elasticsearch實(shí)現(xiàn)集群管理,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
成都創(chuàng)新互聯(lián)主營恒山網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,手機(jī)APP定制開發(fā),恒山h5小程序制作搭建,恒山網(wǎng)站營銷推廣歡迎恒山等地區(qū)企業(yè)咨詢
本篇文章主要是查看集群中的相關(guān)信息,具體請(qǐng)看代碼和注釋
@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服務(wù)器的客戶端 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é)點(diǎn) int numberOfDataNodes = healthResponse.getNumberOfDataNodes(); System.out.println(numberOfDataNodes); //獲取節(jié)點(diǎn)的總數(shù)量 int numberOfNodes = healthResponse.getNumberOfNodes(); System.out.println(numberOfNodes); //獲取集群中一共有多少索引 for(ClusterIndexHealth health:healthResponse.getIndices().values()) { String index = health.getIndex();//當(dāng)前索引名稱 int numberOfShards = health.getNumberOfShards();//主分片 int numberOfReplicas = health.getNumberOfReplicas();//副本 ClusterHealthStatus status = health.getStatus();//得到當(dāng)前的健康狀況 System.out.println(status);//健康-綠色 一般-黃色 不健康-紅色 } }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
網(wǎng)頁標(biāo)題:Java基于elasticsearch實(shí)現(xiàn)集群管理
當(dāng)前URL:http://chinadenli.net/article4/gphpie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、企業(yè)建站、自適應(yīng)網(wǎng)站、動(dòng)態(tài)網(wǎng)站、網(wǎng)站制作、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)