ElasticSearch High Level REST API【6】获取集群信息
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);