recovery.asciidoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. [[indices-recovery]]
  2. === Index recovery API
  3. ++++
  4. <titleabbrev>Index recovery</titleabbrev>
  5. ++++
  6. Returns information about ongoing and completed shard recoveries for one or more
  7. indices. For data streams, the API returns information for the stream's backing
  8. indices.
  9. [source,console]
  10. ----
  11. GET /my-index-000001/_recovery
  12. ----
  13. // TEST[setup:my_index]
  14. [[index-recovery-api-request]]
  15. ==== {api-request-title}
  16. `GET /<target>/_recovery`
  17. `GET /_recovery`
  18. [[index-recovery-api-prereqs]]
  19. ==== {api-prereq-title}
  20. * If the {es} {security-features} are enabled, you must have the `monitor` or
  21. `manage` <<privileges-list-indices,index privilege>> for the target data stream,
  22. index, or index alias.
  23. [[index-recovery-api-desc]]
  24. ==== {api-description-title}
  25. Use the index recovery API
  26. to get information about ongoing and completed shard recoveries.
  27. // tag::shard-recovery-desc[]
  28. Shard recovery is the process
  29. of syncing a replica shard from a primary shard.
  30. Upon completion,
  31. the replica shard is available for search.
  32. include::{es-repo-dir}/glossary.asciidoc[tag=recovery-triggers]
  33. // end::shard-recovery-desc[]
  34. [[index-recovery-api-path-params]]
  35. ==== {api-path-parms-title}
  36. `<target>`::
  37. (Optional, string)
  38. Comma-separated list of data streams, indices, and index aliases used to limit
  39. the request. Wildcard expressions (`*`) are supported.
  40. +
  41. To target all data streams and indices in a cluster, omit this parameter or use
  42. `_all` or `*`.
  43. [[index-recovery-api-query-params]]
  44. ==== {api-query-parms-title}
  45. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=active-only]
  46. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=detailed]
  47. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-query-parm]
  48. [[index-recovery-api-response-body]]
  49. ==== {api-response-body-title}
  50. `id`::
  51. (Integer)
  52. ID of the shard.
  53. `type`::
  54. +
  55. --
  56. (String)
  57. Recovery type.
  58. Returned values include:
  59. `STORE`::
  60. The recovery is related to
  61. a node startup or failure.
  62. This type of recovery is called a local store recovery.
  63. `SNAPSHOT`::
  64. The recovery is related to
  65. a <<snapshots-restore-snapshot,snapshot restoration>>.
  66. `REPLICA`::
  67. The recovery is related to
  68. a <<glossary-replica-shard,primary shard replication>>.
  69. `RELOCATING`::
  70. The recovery is related to
  71. the relocation of a shard
  72. to a different node in the same cluster.
  73. --
  74. `STAGE`::
  75. +
  76. --
  77. (String)
  78. Recovery stage.
  79. Returned values include:
  80. `DONE`::
  81. Complete.
  82. `FINALIZE`::
  83. Cleanup.
  84. `INDEX`::
  85. Reading index metadata and copying bytes from source to destination.
  86. `INIT`::
  87. Recovery has not started.
  88. `START`::
  89. Starting the recovery process; opening the index for use.
  90. `TRANSLOG`::
  91. Replaying transaction log .
  92. --
  93. `primary`::
  94. (Boolean)
  95. If `true`,
  96. the shard is a primary shard.
  97. `start_time`::
  98. (String)
  99. Timestamp of recovery start.
  100. `stop_time`::
  101. (String)
  102. Timestamp of recovery finish.
  103. `total_time_in_millis`::
  104. (String)
  105. Total time to recover shard in milliseconds.
  106. `source`::
  107. +
  108. --
  109. (Object)
  110. Recovery source.
  111. This can include:
  112. * A repository description if recovery is from a snapshot
  113. * A description of source node
  114. --
  115. `target`::
  116. (Object)
  117. Destination node.
  118. `index`::
  119. (Object)
  120. Statistics about physical index recovery.
  121. `translog`::
  122. (Object)
  123. Statistics about translog recovery.
  124. `start`::
  125. (Object)
  126. Statistics about time to open and start the index.
  127. [[index-recovery-api-example]]
  128. ==== {api-examples-title}
  129. [[index-recovery-api-multi-ex]]
  130. ===== Get recovery information for several data streams and indices
  131. [source,console]
  132. --------------------------------------------------
  133. GET index1,index2/_recovery?human
  134. --------------------------------------------------
  135. // TEST[s/^/PUT index1\nPUT index2\n/]
  136. [[index-recovery-api-all-ex]]
  137. ===== Get segment information for all data streams and indices in a cluster
  138. //////////////////////////
  139. Here we create a repository and snapshot index1 in
  140. order to restore it right after and prints out the
  141. index recovery result.
  142. [source,console]
  143. --------------------------------------------------
  144. # create the index
  145. PUT index1
  146. {"settings": {"index.number_of_shards": 1}}
  147. # create the repository
  148. PUT /_snapshot/my_repository
  149. {"type": "fs","settings": {"location": "recovery_asciidoc" }}
  150. # snapshot the index
  151. PUT /_snapshot/my_repository/snap_1?wait_for_completion=true
  152. {"indices": "index1"}
  153. # delete the index
  154. DELETE index1
  155. # and restore the snapshot
  156. POST /_snapshot/my_repository/snap_1/_restore?wait_for_completion=true
  157. --------------------------------------------------
  158. [source,console-result]
  159. --------------------------------------------------
  160. {
  161. "snapshot": {
  162. "snapshot": "snap_1",
  163. "indices": [
  164. "index1"
  165. ],
  166. "shards": {
  167. "total": 1,
  168. "failed": 0,
  169. "successful": 1
  170. }
  171. }
  172. }
  173. --------------------------------------------------
  174. //////////////////////////
  175. [source,console]
  176. --------------------------------------------------
  177. GET /_recovery?human
  178. --------------------------------------------------
  179. // TEST[continued]
  180. The API returns the following response:
  181. [source,console-result]
  182. --------------------------------------------------
  183. {
  184. "index1" : {
  185. "shards" : [ {
  186. "id" : 0,
  187. "type" : "SNAPSHOT",
  188. "stage" : "INDEX",
  189. "primary" : true,
  190. "start_time" : "2014-02-24T12:15:59.716",
  191. "start_time_in_millis": 1393244159716,
  192. "stop_time" : "0s",
  193. "stop_time_in_millis" : 0,
  194. "total_time" : "2.9m",
  195. "total_time_in_millis" : 175576,
  196. "source" : {
  197. "repository" : "my_repository",
  198. "snapshot" : "my_snapshot",
  199. "index" : "index1",
  200. "version" : "{version}",
  201. "restoreUUID": "PDh1ZAOaRbiGIVtCvZOMww"
  202. },
  203. "target" : {
  204. "id" : "ryqJ5lO5S4-lSFbGntkEkg",
  205. "host" : "my.fqdn",
  206. "transport_address" : "my.fqdn",
  207. "ip" : "10.0.1.7",
  208. "name" : "my_es_node"
  209. },
  210. "index" : {
  211. "size" : {
  212. "total" : "75.4mb",
  213. "total_in_bytes" : 79063092,
  214. "reused" : "0b",
  215. "reused_in_bytes" : 0,
  216. "recovered" : "65.7mb",
  217. "recovered_in_bytes" : 68891939,
  218. "percent" : "87.1%"
  219. },
  220. "files" : {
  221. "total" : 73,
  222. "reused" : 0,
  223. "recovered" : 69,
  224. "percent" : "94.5%"
  225. },
  226. "total_time" : "0s",
  227. "total_time_in_millis" : 0,
  228. "source_throttle_time" : "0s",
  229. "source_throttle_time_in_millis" : 0,
  230. "target_throttle_time" : "0s",
  231. "target_throttle_time_in_millis" : 0
  232. },
  233. "translog" : {
  234. "recovered" : 0,
  235. "total" : 0,
  236. "percent" : "100.0%",
  237. "total_on_start" : 0,
  238. "total_time" : "0s",
  239. "total_time_in_millis" : 0,
  240. },
  241. "verify_index" : {
  242. "check_index_time" : "0s",
  243. "check_index_time_in_millis" : 0,
  244. "total_time" : "0s",
  245. "total_time_in_millis" : 0
  246. }
  247. } ]
  248. }
  249. }
  250. --------------------------------------------------
  251. // TESTRESPONSE[s/: (\-)?[0-9]+/: $body.$_path/]
  252. // TESTRESPONSE[s/: "[^"]*"/: $body.$_path/]
  253. ////
  254. The TESTRESPONSE above replace all the fields values by the expected ones in the test,
  255. because we don't really care about the field values but we want to check the fields names.
  256. ////
  257. This response includes information
  258. about a single index recovering a single shard.
  259. The source of the recovery is a snapshot repository
  260. and the target of the recovery is the `my_es_node` node.
  261. The response also includes the number
  262. and percentage of files and bytes recovered.
  263. [[index-recovery-api-detailed-ex]]
  264. ===== Get detailed recovery information
  265. To get a list of physical files in recovery,
  266. set the `detailed` query parameter to `true`.
  267. [source,console]
  268. --------------------------------------------------
  269. GET _recovery?human&detailed=true
  270. --------------------------------------------------
  271. // TEST[s/^/PUT index1\n{"settings": {"index.number_of_shards": 1}}\n/]
  272. The API returns the following response:
  273. [source,console-result]
  274. --------------------------------------------------
  275. {
  276. "index1" : {
  277. "shards" : [ {
  278. "id" : 0,
  279. "type" : "STORE",
  280. "stage" : "DONE",
  281. "primary" : true,
  282. "start_time" : "2014-02-24T12:38:06.349",
  283. "start_time_in_millis" : "1393245486349",
  284. "stop_time" : "2014-02-24T12:38:08.464",
  285. "stop_time_in_millis" : "1393245488464",
  286. "total_time" : "2.1s",
  287. "total_time_in_millis" : 2115,
  288. "source" : {
  289. "id" : "RGMdRc-yQWWKIBM4DGvwqQ",
  290. "host" : "my.fqdn",
  291. "transport_address" : "my.fqdn",
  292. "ip" : "10.0.1.7",
  293. "name" : "my_es_node"
  294. },
  295. "target" : {
  296. "id" : "RGMdRc-yQWWKIBM4DGvwqQ",
  297. "host" : "my.fqdn",
  298. "transport_address" : "my.fqdn",
  299. "ip" : "10.0.1.7",
  300. "name" : "my_es_node"
  301. },
  302. "index" : {
  303. "size" : {
  304. "total" : "24.7mb",
  305. "total_in_bytes" : 26001617,
  306. "reused" : "24.7mb",
  307. "reused_in_bytes" : 26001617,
  308. "recovered" : "0b",
  309. "recovered_in_bytes" : 0,
  310. "percent" : "100.0%"
  311. },
  312. "files" : {
  313. "total" : 26,
  314. "reused" : 26,
  315. "recovered" : 0,
  316. "percent" : "100.0%",
  317. "details" : [ {
  318. "name" : "segments.gen",
  319. "length" : 20,
  320. "recovered" : 20
  321. }, {
  322. "name" : "_0.cfs",
  323. "length" : 135306,
  324. "recovered" : 135306
  325. }, {
  326. "name" : "segments_2",
  327. "length" : 251,
  328. "recovered" : 251
  329. }
  330. ]
  331. },
  332. "total_time" : "2ms",
  333. "total_time_in_millis" : 2,
  334. "source_throttle_time" : "0s",
  335. "source_throttle_time_in_millis" : 0,
  336. "target_throttle_time" : "0s",
  337. "target_throttle_time_in_millis" : 0
  338. },
  339. "translog" : {
  340. "recovered" : 71,
  341. "total" : 0,
  342. "percent" : "100.0%",
  343. "total_on_start" : 0,
  344. "total_time" : "2.0s",
  345. "total_time_in_millis" : 2025
  346. },
  347. "verify_index" : {
  348. "check_index_time" : 0,
  349. "check_index_time_in_millis" : 0,
  350. "total_time" : "88ms",
  351. "total_time_in_millis" : 88
  352. }
  353. } ]
  354. }
  355. }
  356. --------------------------------------------------
  357. // TESTRESPONSE[s/"source" : \{[^}]*\}/"source" : $body.$_path/]
  358. // TESTRESPONSE[s/"details" : \[[^\]]*\]/"details" : $body.$_path/]
  359. // TESTRESPONSE[s/: (\-)?[0-9]+/: $body.$_path/]
  360. // TESTRESPONSE[s/: "[^"]*"/: $body.$_path/]
  361. ////
  362. The TESTRESPONSE above replace all the fields values by the expected ones in the test,
  363. because we don't really care about the field values but we want to check the fields names.
  364. It also removes the "details" part which is important in this doc but really hard to test.
  365. ////
  366. The response includes a listing
  367. of any physical files recovered
  368. and their sizes.
  369. The response also includes timings in milliseconds
  370. of the various stages of recovery:
  371. * Index retrieval
  372. * Translog replay
  373. * Index start time
  374. This response indicates the recovery is `done`.
  375. All recoveries,
  376. whether ongoing or complete,
  377. are kept in the cluster state
  378. and may be reported on at any time.
  379. To only return information about ongoing recoveries,
  380. set the `active_only` query parameter to `true`.