health.asciidoc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. [[cluster-health]]
  2. === Cluster health API
  3. ++++
  4. <titleabbrev>Cluster health</titleabbrev>
  5. ++++
  6. .New API reference
  7. [sidebar]
  8. --
  9. For the most up-to-date API details, refer to {api-es}/group/endpoint-cluster[Cluster APIs].
  10. --
  11. Returns the health status of a cluster.
  12. [[cluster-health-api-request]]
  13. ==== {api-request-title}
  14. `GET /_cluster/health/<target>`
  15. [[cluster-health-api-prereqs]]
  16. ==== {api-prereq-title}
  17. * If the {es} {security-features} are enabled, you must have the `monitor` or
  18. `manage` <<privileges-list-cluster,cluster privilege>> to use this API.
  19. [[cluster-health-api-desc]]
  20. ==== {api-description-title}
  21. The cluster health API returns a simple status on the health of the
  22. cluster. You can also use the API to get the health status of only specified
  23. data streams and indices. For data streams, the API retrieves the health status
  24. of the stream's backing indices.
  25. The cluster health status is: `green`, `yellow` or `red`. On the shard level, a
  26. `red` status indicates that the specific shard is not allocated in the cluster,
  27. `yellow` means that the primary shard is allocated but replicas are not, and
  28. `green` means that all shards are allocated. The index level status is
  29. controlled by the worst shard status. The cluster status is controlled by the
  30. worst index status.
  31. One of the main benefits of the API is the ability to wait until the cluster
  32. reaches a certain high water-mark health level. For example, the following will
  33. wait for 50 seconds for the cluster to reach the `yellow` level (if it reaches
  34. the `green` or `yellow` status before 50 seconds elapse, it will return at that
  35. point):
  36. [source,console]
  37. --------------------------------------------------
  38. GET /_cluster/health?wait_for_status=yellow&timeout=50s
  39. --------------------------------------------------
  40. [[cluster-health-api-path-params]]
  41. ==== {api-path-parms-title}
  42. `<target>`::
  43. (Optional, string)
  44. Comma-separated list of data streams, indices, and index aliases used to limit
  45. the request. Wildcard expressions (`*`) are supported.
  46. +
  47. To target all data streams and indices in a cluster, omit this parameter or use
  48. `_all` or `*`.
  49. [[cluster-health-api-query-params]]
  50. ==== {api-query-parms-title}
  51. `level`::
  52. (Optional, string) Can be one of `cluster`, `indices` or `shards`. Controls
  53. the details level of the health information returned. Defaults to `cluster`.
  54. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=local]
  55. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  56. `wait_for_active_shards`::
  57. (Optional, string) A number controlling to how many active shards to wait
  58. for, `all` to wait for all shards in the cluster to be active, or `0` to not
  59. wait. Defaults to `0`.
  60. `wait_for_events`::
  61. (Optional, string) Can be one of `immediate`, `urgent`, `high`, `normal`,
  62. `low`, `languid`. Wait until all currently queued events with the given
  63. priority are processed.
  64. `wait_for_no_initializing_shards`::
  65. (Optional, Boolean) A boolean value which controls whether to wait (until
  66. the timeout provided) for the cluster to have no shard initializations.
  67. Defaults to false, which means it will not wait for initializing shards.
  68. `wait_for_no_relocating_shards`::
  69. (Optional, Boolean) A boolean value which controls whether to wait (until
  70. the timeout provided) for the cluster to have no shard relocations. Defaults
  71. to false, which means it will not wait for relocating shards.
  72. `wait_for_nodes`::
  73. (Optional, string) The request waits until the specified number `N` of
  74. nodes is available. It also accepts `>=N`, `<=N`, `>N` and `<N`.
  75. Alternatively, it is possible to use `ge(N)`, `le(N)`, `gt(N)` and
  76. `lt(N)` notation.
  77. `wait_for_status`::
  78. (Optional, string) One of `green`, `yellow` or `red`. Will wait (until the
  79. timeout provided) until the status of the cluster changes to the one
  80. provided or better, i.e. `green` > `yellow` > `red`. By default, will not
  81. wait for any status.
  82. [[cluster-health-api-response-body]]
  83. ==== {api-response-body-title}
  84. `cluster_name`::
  85. (string) The name of the cluster.
  86. `status`::
  87. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=cluster-health-status]
  88. `timed_out`::
  89. (Boolean) If `false` the response returned within the period of
  90. time that is specified by the `timeout` parameter (`30s` by default).
  91. `number_of_nodes`::
  92. (integer) The number of nodes within the cluster.
  93. `number_of_data_nodes`::
  94. (integer) The number of nodes that are dedicated data nodes.
  95. `active_primary_shards`::
  96. (integer) The number of active primary shards.
  97. `active_shards`::
  98. (integer) The total number of active primary and replica shards.
  99. `relocating_shards`::
  100. (integer) The number of shards that are under relocation.
  101. `initializing_shards`::
  102. (integer) The number of shards that are under initialization.
  103. `unassigned_shards`::
  104. (integer) The number of shards that are not allocated.
  105. `unassigned_primary_shards`::
  106. (integer) The number of shards that are primary but not allocated. **Note**: This number may be lower than the true value if your cluster contains nodes running a version below 8.16. For a more accurate count in this scenario, please use the <<cluster-health,cluster health API>>.
  107. `delayed_unassigned_shards`::
  108. (integer) The number of shards whose allocation has been delayed by the
  109. timeout settings.
  110. `number_of_pending_tasks`::
  111. (integer) The number of cluster-level changes that have not yet been
  112. executed.
  113. `number_of_in_flight_fetch`::
  114. (integer) The number of unfinished fetches.
  115. `task_max_waiting_in_queue_millis`::
  116. (integer) The time expressed in milliseconds since the earliest initiated task
  117. is waiting for being performed.
  118. `active_shards_percent_as_number`::
  119. (float) The ratio of active shards in the cluster expressed as a percentage.
  120. [[cluster-health-api-example]]
  121. ==== {api-examples-title}
  122. [source,console]
  123. --------------------------------------------------
  124. GET _cluster/health
  125. --------------------------------------------------
  126. // TEST[s/^/PUT test1\n/]
  127. The API returns the following response in case of a quiet single node cluster
  128. with a single index with one shard and one replica:
  129. [source,console-result]
  130. --------------------------------------------------
  131. {
  132. "cluster_name" : "testcluster",
  133. "status" : "yellow",
  134. "timed_out" : false,
  135. "number_of_nodes" : 1,
  136. "number_of_data_nodes" : 1,
  137. "active_primary_shards" : 1,
  138. "active_shards" : 1,
  139. "relocating_shards" : 0,
  140. "initializing_shards" : 0,
  141. "unassigned_shards" : 1,
  142. "unassigned_primary_shards" : 0,
  143. "delayed_unassigned_shards": 0,
  144. "number_of_pending_tasks" : 0,
  145. "number_of_in_flight_fetch": 0,
  146. "task_max_waiting_in_queue_millis": 0,
  147. "active_shards_percent_as_number": 50.0
  148. }
  149. --------------------------------------------------
  150. // TESTRESPONSE[s/testcluster/yamlRestTest/]
  151. // TESTRESPONSE[s/"number_of_pending_tasks" : 0,/"number_of_pending_tasks" : $body.number_of_pending_tasks,/]
  152. // TESTRESPONSE[s/"task_max_waiting_in_queue_millis": 0/"task_max_waiting_in_queue_millis": $body.task_max_waiting_in_queue_millis/]
  153. The following is an example of getting the cluster health at the
  154. `shards` level:
  155. [source,console]
  156. --------------------------------------------------
  157. GET /_cluster/health/my-index-000001?level=shards
  158. --------------------------------------------------
  159. // TEST[setup:my_index]