cluster health API能够得到一个非常简单的集群健康状态。
$ curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
{
"cluster_name" : "testcluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 2,
"number_of_data_nodes" : 2,
"active_primary_shards" : 5,
"active_shards" : 10,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0
}
这个API也能在一个或多个索引上执行,得到指定索引的健康状态:
$ curl -XGET 'http://localhost:9200/_cluster/health/test1,test2'
集群健康状态是:green,yellow和red。在分片层次上,一个red状态表明这个指定的分片没有分配,yellow表示主分片分配但副本没有分配,green表示所有的分片都已经分配。索引级别的状态由分片的最差状态决定。集群状态由最差的索引状态控制。
这个API的主要好处之一是能够等到集群达到一定高的级别。例如,下面的指令在集群达到yellow状态前会等待50s(在50s前,如果达到green或yellow状态,则返回):
$ curl -XGET 'http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=50s'