health.asciidoc 6.6 KB

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