溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Java基于elasticsearch實現(xiàn)集群管理

發(fā)布時間:2020-09-19 00:01:01 來源:腳本之家 閱讀:130 作者:陳遠波 欄目:編程語言

這篇文章主要介紹了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)容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI