Elasticsearch专题精讲—— REST APIs —— Cluster APIs —— Cluster health API

REST APIs —— Cluster APIs —— Cluster health API

https://www.elastic.co/guide/en/elasticsearch/reference/8.8/cluster-health.html#cluster-health

Returns the health status of a cluster.

返回集群的健康状态。

1、Request(请求)

https://www.elastic.co/guide/en/elasticsearch/reference/8.8/cluster-health.html#cluster-health-api-request

        GET /_cluster/health/< target>
        

2、Prerequisites(先决条件)

https://www.elastic.co/guide/en/elasticsearch/reference/8.8/cluster-health.html#cluster-health-api-prereqs

If the Elasticsearch security features are enabled, you must have the monitor or manage cluster privilege to use this API.

如果启用了 Elasticsearch 安全特性,则必须拥有监视器或管理集群特权才能使用此 API。

3、Description(描述)

https://www.elastic.co/guide/en/elasticsearch/reference/8.8/cluster-health.html#cluster-health-api-desc

The cluster health API returns a simple status on the health of the cluster. You can also use the API to get the health status of only specified data streams and indices. For data streams, the API retrieves the health status of the stream’s backing indices.

集群健康API返回有关集群健康状态的简单状态。您还可以使用此API来获取仅指定数据流和索引的健康状态。对于数据流,该API检索流支持的索引的健康状态。

The cluster health status is: green, yellow or red. On the shard level, a red status indicates that the specific shard is not allocated in the cluster, yellow means that the primary shard is allocated but replicas are not, and green means that all shards are allocated. The index level status is controlled by the worst shard status. The cluster status is controlled by the worst index status.

群集健康状态为: 绿色、黄色或红色。在分片级别上,红色状态表示没有在集群中分配特定的分片,黄色表示分配了主分片,但没有分配副本,绿色表示分配了所有分片。索引级别状态由最差的分片状态控制。簇状态由最差索引状态控制。

One of the main benefits of the API is the ability to wait until the cluster reaches a certain high water-mark health level. For example, the following will wait for 50 seconds for the cluster to reach the yellow level (if it reaches the green or yellow status before 50 seconds elapse, it will return at that point):

API 的主要好处之一是能够等待,直到集群达到一定的高水位健康水平。例如,下面的代码会等待50秒,等待集群到达黄色级别(如果在50秒之前它到达绿色或黄色状态,它将在该点返回):

        curl -X GET "localhost:9200/_cluster/health?wait_for_status=yellow&timeout=50s&pretty"

4、Example(例子)

https://www.elastic.co/guide/en/elasticsearch/reference/8.8/cluster-health.html#cluster-health-api-example

        curl -X GET "localhost:9200/_cluster/health?pretty"
        

The API returns the following response in case of a quiet single node cluster with a single index with one shard and one replica:

如果是一个安静的单节点集群,并且只有一个索引,其中包含一个分片和一个副本,则API返回以下响应:

        {
            "cluster_name" : "testcluster", // 集群名称
            "status" : "yellow", // 集群健康状态,黄色表示部分分片不可用
            "timed_out" : false, // 是否在指定时间内完成请求
            "number_of_nodes" : 1, // 集群中节点的数量
            "number_of_data_nodes" : 1, // 数据节点的数量
            "active_primary_shards" : 1, // 集群中主分片的数量
            "active_shards" : 1, // 集群中所有可用分片的数量,包括主分片和副本分片
            "relocating_shards" : 0, // 正在迁移的分片数量
            "initializing_shards" : 0, // 正在初始化的分片数量
            "unassigned_shards" : 1, // 未分配分片的数量
            "delayed_unassigned_shards": 0, // 延迟未分配分片的数量
            "number_of_pending_tasks" : 0, // 等待执行的任务数
            "number_of_in_flight_fetch": 0, // 正在进行的Fetch请求数量
            "task_max_waiting_in_queue_millis": 0, // 在队列中等待最长的任务等待时间
            "active_shards_percent_as_number": 50.0 // 可用分片百分比,浮点数类型
          }

The following is an example of getting the cluster health at the shards level:

以下是在分片级别实现集群健康的一个例子:

        curl -X GET "localhost:9200/_cluster/health/my-index-000001?level=shards&pretty"
    
posted @ 2023-06-24 22:53  左扬  阅读(33)  评论(0编辑  收藏  举报
levels of contents