ElasticSearch 可以通過info()
方法檢索群集信息:
public void info(){ RestHighLevelClient client = elasticClient.getRestHighLevelClient(); MainResponse response = null; try { response = client.info(RequestOptions.DEFAULT); } catch (IOException e) { e.printStackTrace(); } //返回集群的各種信息 ClusterName clusterName = response.getClusterName(); //集群名稱 String clusterUuid = response.getClusterUuid(); //群集的唯一標識符 String nodeName = response.getNodeName(); //已執行請求的節點的名稱 Version version = response.getVersion(); //已執行請求的節點的版本 Build build = response.getBuild(); //已執行請求的節點的構建信息 }
Ping API
通過使用ping()
方法可以檢查集群是否連接成功,並返回一個布爾值:
boolean response = client.ping(RequestOptions.DEFAULT);