update-lifecycle-policy.asciidoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[update-lifecycle-policy]]
  4. == Update lifecycle policy
  5. ++++
  6. <titleabbrev>Update policy</titleabbrev>
  7. ++++
  8. You can update an existing lifecycle policy to fix mistakes or change
  9. strategies for newly created indices. It is possible to update policy definitions
  10. and an index's `index.lifecycle.name` settings independently. To prevent the situation
  11. that phase definitions are modified while currently being executed on an index, each index
  12. will keep the version of the current phase definition it began execution with until it completes.
  13. This also means that changes to `min_age` will not be propagated. If a new policy is set that
  14. introduces a later `min_age` for the currently executing phase, that new `min_age` will not
  15. be picked up by the update.
  16. There are three scenarios for examining the behavior updating policies and
  17. their effects on policy execution on indices.
  18. === Updates to policies not managing indices
  19. Indices not referencing an existing policy that is updated will not be affected.
  20. If an index is assigned to the policy, it will be assigned the latest version of that policy
  21. To show this, let's create a policy `my_policy`.
  22. [source,js]
  23. ------------------------
  24. PUT _ilm/policy/my_policy
  25. {
  26. "policy": {
  27. "phases": {
  28. "hot": {
  29. "actions": {
  30. "rollover": {
  31. "max_size": "25GB"
  32. }
  33. }
  34. },
  35. "delete": {
  36. "min_age": "30d",
  37. "actions": {
  38. "delete": {}
  39. }
  40. }
  41. }
  42. }
  43. }
  44. ------------------------
  45. // CONSOLE
  46. This newly defined policy will be created and assigned to have a version equal
  47. to 1. Since we haven't assigned any indices to this policy, any updates that
  48. occur will be reflected completely on indices that are newly set to be managed
  49. by this policy.
  50. Updating the Delete phase's minimum age can be done in an update request.
  51. [source,js]
  52. ------------------------
  53. PUT _ilm/policy/my_policy
  54. {
  55. "policy": {
  56. "phases": {
  57. "hot": {
  58. "actions": {
  59. "rollover": {
  60. "max_size": "25GB"
  61. }
  62. }
  63. },
  64. "delete": {
  65. "min_age": "10d", <1>
  66. "actions": {
  67. "delete": {}
  68. }
  69. }
  70. }
  71. }
  72. }
  73. ------------------------
  74. // CONSOLE
  75. // TEST[continued]
  76. <1> update `min_age` to 10 days
  77. //////////
  78. [source,js]
  79. --------------------------------------------------
  80. GET _ilm/policy/my_policy
  81. --------------------------------------------------
  82. // CONSOLE
  83. // TEST[continued]
  84. //////////
  85. When we get the policy, we will see it reflect our latest changes, but
  86. with its version bumped to 2.
  87. [source,js]
  88. --------------------------------------------------
  89. {
  90. "my_policy": {
  91. "version": 2, <1>
  92. "modified_date": 82392349, <2>
  93. "policy": {
  94. "phases": {
  95. "hot": {
  96. "min_age": "0ms",
  97. "actions": {
  98. "rollover": {
  99. "max_size": "25gb"
  100. }
  101. }
  102. },
  103. "delete": {
  104. "min_age": "10d",
  105. "actions": {
  106. "delete": {}
  107. }
  108. }
  109. }
  110. }
  111. }
  112. }
  113. --------------------------------------------------
  114. // CONSOLE
  115. // TESTRESPONSE[s/"modified_date": 82392349/"modified_date": $body.my_policy.modified_date/]
  116. <1> The updated version value
  117. <2> The timestamp when this policy was updated last.
  118. Afterwords, any indices set to `my_policy` will execute against version 2 of
  119. the policy.
  120. === Updates to executing policies
  121. Indices preserve the phase definition from the latest policy version that existed
  122. at the time that it entered that phase. Changes to the currently-executing phase within policy updates will
  123. not be reflected during execution. This means that updates to the `hot` phase, for example, will not affect
  124. indices that are currently executing the corresponding `hot` phase.
  125. Let's say we have an index `my_index` managed by the below `my_executing_policy` definition.
  126. [source,js]
  127. ------------------------
  128. PUT _ilm/policy/my_executing_policy
  129. {
  130. "policy": {
  131. "phases": {
  132. "hot": {
  133. "actions": {
  134. "rollover": {
  135. "max_docs": 1
  136. }
  137. }
  138. },
  139. "delete": {
  140. "min_age": "10d",
  141. "actions": {
  142. "delete": {}
  143. }
  144. }
  145. }
  146. }
  147. }
  148. ------------------------
  149. // CONSOLE
  150. ////
  151. [source,js]
  152. ------------------------
  153. PUT my_index
  154. {
  155. "settings": {
  156. "index.lifecycle.name": "my_executing_policy"
  157. }
  158. }
  159. ------------------------
  160. // CONSOLE
  161. // TEST[continued]
  162. ////
  163. The <<ilm-explain-lifecycle,Explain API>> is useful to introspect managed indices to see which phase definition they are currently executing.
  164. Using this API, we can find out that `my_index` is currently checking if it is ready to be rolled over.
  165. [source,js]
  166. --------------------------------------------------
  167. GET my_index/_ilm/explain
  168. --------------------------------------------------
  169. // CONSOLE
  170. // TEST[continued]
  171. [source,js]
  172. --------------------------------------------------
  173. {
  174. "indices": {
  175. "my_index": {
  176. "index": "my_index",
  177. "managed": true,
  178. "policy": "my_executing_policy",
  179. "lifecycle_date_millis": 1538475653281,
  180. "age": "30s",
  181. "phase": "hot",
  182. "phase_time_millis": 1538475653317,
  183. "action": "rollover",
  184. "action_time_millis": 1538475653317,
  185. "step": "check-rollover-ready",
  186. "step_time_millis": 1538475653317,
  187. "phase_execution": {
  188. "policy": "my_executing_policy",
  189. "modified_date_in_millis": 1538475653317,
  190. "version": 1,
  191. "phase_definition": {
  192. "min_age": "0ms",
  193. "actions": {
  194. "rollover": {
  195. "max_docs": 1
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. --------------------------------------------------
  204. // CONSOLE
  205. // TESTRESPONSE[skip:no way to know if we will get this response immediately]
  206. We can update `my_executing_policy` to enter the hot phase after one day.
  207. [source,js]
  208. ------------------------
  209. PUT _ilm/policy/my_executing_policy
  210. {
  211. "policy": {
  212. "phases": {
  213. "hot": {
  214. "min_age": "1d", <1>
  215. "actions": {
  216. "rollover": {
  217. "max_docs": 1
  218. }
  219. }
  220. },
  221. "delete": {
  222. "min_age": "10d",
  223. "actions": {
  224. "delete": {}
  225. }
  226. }
  227. }
  228. }
  229. }
  230. ------------------------
  231. // CONSOLE
  232. // TEST[continued]
  233. <1> updated `min_age` from "0ms" to "1d"
  234. The index `my_index` has already entered the hot phase, so it will still
  235. use version 1 of the policy until it completes the hot phase.
  236. ////
  237. [source,js]
  238. --------------------------------------------------
  239. GET my_index/_ilm/explain
  240. --------------------------------------------------
  241. // CONSOLE
  242. // TEST[continued]
  243. ////
  244. [source,js]
  245. --------------------------------------------------
  246. {
  247. "indices": {
  248. "my_index": {
  249. "index": "my_index",
  250. "managed": true,
  251. "policy": "my_executing_policy",
  252. "lifecycle_date_millis": 1538475653281,
  253. "age": "30s",
  254. "phase": "hot",
  255. "phase_time_millis": 1538475653317,
  256. "action": "rollover",
  257. "action_time_millis": 1538475653317,
  258. "step": "check-rollover-ready",
  259. "step_time_millis": 1538475653317,
  260. "phase_execution": {
  261. "policy": "my_executing_policy",
  262. "modified_date_in_millis": 1538475653317,
  263. "version": 1, <1>
  264. "phase_definition": {
  265. "min_age": "0ms",
  266. "actions": {
  267. "rollover": {
  268. "max_docs": 1
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }
  275. }
  276. --------------------------------------------------
  277. // CONSOLE
  278. // TESTRESPONSE[skip:no way to know if we will get this response immediately]
  279. <1> the version of the policy used for executing the hot phase
  280. We can also update `my_executing_policy` to have no rollover action and,
  281. instead, go directly into a newly introduced `warm` phase.
  282. [source,js]
  283. ------------------------
  284. PUT _ilm/policy/my_executing_policy
  285. {
  286. "policy": {
  287. "phases": {
  288. "warm": {
  289. "min_age": "1d",
  290. "actions": {
  291. "forcemerge": {
  292. "max_num_segments": 1
  293. }
  294. }
  295. },
  296. "delete": {
  297. "min_age": "10d",
  298. "actions": {
  299. "delete": {}
  300. }
  301. }
  302. }
  303. }
  304. }
  305. ------------------------
  306. // CONSOLE
  307. // TEST[continued]
  308. Now, version 3 of this policy has no `hot` phase, but if we run the
  309. Explain API again, we will see that nothing has changed. The index
  310. `my_index` is still executing version 1 of the policy.
  311. ////
  312. [source,js]
  313. --------------------------------------------------
  314. GET my_index/_ilm/explain
  315. --------------------------------------------------
  316. // CONSOLE
  317. // TEST[continued]
  318. ////
  319. [source,js]
  320. --------------------------------------------------
  321. {
  322. "indices": {
  323. "my_index": {
  324. "index": "my_index",
  325. "managed": true,
  326. "policy": "my_executing_policy",
  327. "lifecycle_date_millis": 1538475653281,
  328. "age": "30s",
  329. "phase": "hot",
  330. "phase_time_millis": 1538475653317,
  331. "action": "rollover",
  332. "action_time_millis": 1538475653317,
  333. "step": "check-rollover-ready",
  334. "step_time_millis": 1538475653317,
  335. "phase_execution": {
  336. "policy": "my_executing_policy",
  337. "modified_date_in_millis": 1538475653317,
  338. "version": 1, <1>
  339. "phase_definition": {
  340. "min_age": "0ms",
  341. "actions": {
  342. "rollover": {
  343. "max_docs": 1
  344. }
  345. }
  346. }
  347. }
  348. }
  349. }
  350. }
  351. --------------------------------------------------
  352. // CONSOLE
  353. // TESTRESPONSE[skip:no way to know if we will get this response immediately]
  354. <1> the version of the policy used for executing the hot phase
  355. After indexing one document into `my_index` so that rollover succeeds and
  356. moves onto the next phase, we will notice something new. The index will
  357. move into the next phase in the updated version 3 of its policy.
  358. ////
  359. [source,js]
  360. --------------------------------------------------
  361. PUT my_index/_doc/1
  362. {
  363. "foo": "bar"
  364. }
  365. GET my_index/_ilm/explain
  366. --------------------------------------------------
  367. // CONSOLE
  368. // TEST[continued]
  369. ////
  370. [source,js]
  371. --------------------------------------------------
  372. {
  373. "indices": {
  374. "my_index": {
  375. "index": "my_index",
  376. "managed": true,
  377. "policy": "my_executing_policy",
  378. "lifecycle_date_millis": 1538475653281,
  379. "age": "30s",
  380. "phase": "warm",
  381. "phase_time_millis": 1538475653317,
  382. "action": "forcemerge",
  383. "action_time_millis": 1538475653317,
  384. "step": "forcemerge",
  385. "step_time_millis": 1538475653317,
  386. "phase_execution": {
  387. "policy": "my_executing_policy",
  388. "modified_date_in_millis": 1538475653317,
  389. "version": 3, <1>
  390. "phase_definition": {
  391. "min_age": "1d",
  392. "actions": {
  393. "forcemerge": {
  394. "max_num_segments": 1
  395. }
  396. }
  397. }
  398. }
  399. }
  400. }
  401. }
  402. --------------------------------------------------
  403. // CONSOLE
  404. // TESTRESPONSE[skip:There is no way to force the index to move to the next step in a timely manner]
  405. <1> The index has moved to using version 3 of the policy
  406. `my_index` will move to the next phase in the latest policy definition, which is the newly added `warm` phase.
  407. === Switching policies for an index
  408. Setting `index.lifecycle.name` to a different policy behaves much like a policy update, but instead of just
  409. switching to a different version, it switches to a different policy.
  410. After setting a policy for an index, we can switch out `my_policy` with
  411. `my_other_policy` by just updating the index's `index.lifecycle.name`
  412. setting to the new policy. After completing its currently executed phase,
  413. it will move on to the next phase in `my_other_policy`. So if it was on the
  414. `hot` phase before, it will move to the `delete` phase after the `hot` phase concluded.
  415. ////
  416. [source,js]
  417. ------------------------
  418. PUT _ilm/policy/my_policy
  419. {
  420. "policy": {
  421. "phases": {
  422. "hot": {
  423. "actions": {
  424. "rollover": {
  425. "max_size": "25GB"
  426. }
  427. }
  428. },
  429. "delete": {
  430. "min_age": "10d",
  431. "actions": {
  432. "delete": {}
  433. }
  434. }
  435. }
  436. }
  437. }
  438. PUT _ilm/policy/my_other_policy
  439. {
  440. "policy": {
  441. "phases": {
  442. "delete": {
  443. "min_age": "1d",
  444. "actions": {
  445. "delete": {}
  446. }
  447. }
  448. }
  449. }
  450. }
  451. PUT my_index
  452. {
  453. "settings": {
  454. "index.lifecycle.name": "my_policy"
  455. }
  456. }
  457. ------------------------
  458. // CONSOLE
  459. ////
  460. [source,js]
  461. --------------------------------------------------
  462. PUT my_index/_settings
  463. {
  464. "lifecycle.name": "my_other_policy"
  465. }
  466. --------------------------------------------------
  467. // CONSOLE
  468. // TEST[continued]
  469. The change to the new policy will not happen immediately. The currently executing phase
  470. of the existing policy for `my_index` will continue to execute until it completes. Once
  471. completed, `my_index` will move to being managed by the `my_other_policy`.