recovery.asciidoc 11 KB

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