policy-definitions.asciidoc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[ilm-policy-definition]]
  4. == Policy phases and actions
  5. There are four stages in the index lifecycle, in the order
  6. they are executed.
  7. [options="header"]
  8. |======
  9. | Name | Description
  10. | `hot` | The index is actively being written to
  11. | `warm` | The index is generally not being written to, but is still queried
  12. | `cold` | The index is no longer being updated and is seldom queried. The
  13. information still needs to be searchable, but it's okay if those queries are
  14. slower.
  15. | `delete` | The index is no longer needed and can safely be deleted
  16. |======
  17. Each of these stages is called a "phase". A policy does not need to configure
  18. each phase for an index. For example, one policy may define only the hot
  19. phase and the delete phase, while another may define all four phases.
  20. === Timing
  21. Indices enter phases based on a phase's `min_age` parameter.
  22. The index will not enter the phase until the index's age is older than that
  23. of the `min_age`. The parameter is configured using a time
  24. duration format (see <<time-units, Time Units>>).
  25. `min_age` defaults to zero seconds `0s` for each phase if not specified.
  26. [source,js]
  27. --------------------------------------------------
  28. PUT _ilm/policy/my_policy
  29. {
  30. "policy": {
  31. "phases": {
  32. "warm": {
  33. "min_age": "1d",
  34. "actions": {
  35. "allocate": {
  36. "number_of_replicas": 1
  37. }
  38. }
  39. },
  40. "delete": {
  41. "min_age": "30d",
  42. "actions": {
  43. "delete": {}
  44. }
  45. }
  46. }
  47. }
  48. }
  49. --------------------------------------------------
  50. // CONSOLE
  51. The Above example configures a policy that moves the index into the warm
  52. phase after one day. Until then, the index is in a waiting state. After
  53. moving into the warm phase, it will wait until 30 days have elapsed before
  54. moving to the delete phase and deleting the index.
  55. `min_age` is usually the time elapsed from the time the index is created. If the
  56. index is rolled over, then `min_age` is the time elapsed from the time the index
  57. is rolled over. The intention here is to execute following phases and actions
  58. relative to when data was written last to a rolled over index.
  59. The previous phase's actions must complete before {ilm} will check `min_age` and
  60. transition into the next phase. By default, {ilm} checks for indices that meet
  61. policy criteria, like `min_age`, every 10 minutes. You can use the
  62. `indices.lifecycle.poll_interval` cluster setting to control how often this
  63. check occurs.
  64. === Phase Execution
  65. The current phase definition, of an index's policy being executed, is stored
  66. in the index's metadata. The phase and its actions are compiled into a series
  67. of discrete steps that are executed sequentially. Since some {ilm-init} actions
  68. are more complex and involve multiple operations against an index, each of these
  69. operations are done in isolation in a unit called a "step". The
  70. <<ilm-explain-lifecycle,Explain Lifecycle API>> exposes this information to us
  71. to see which step our index is either to execute next, or is currently
  72. executing.
  73. === Actions
  74. The below list shows the actions which are available in each phase.
  75. NOTE: The order that configured actions are performed in within each phase is
  76. determined by automatically by {ilm-init}, and cannot be changed by changing the
  77. policy definition.
  78. * Hot
  79. - <<ilm-set-priority-action,Set Priority>>
  80. - <<ilm-unfollow-action,Unfollow>>
  81. - <<ilm-rollover-action,Rollover>>
  82. * Warm
  83. - <<ilm-set-priority-action,Set Priority>>
  84. - <<ilm-unfollow-action,Unfollow>>
  85. - <<ilm-readonly-action,Read-Only>>
  86. - <<ilm-allocate-action,Allocate>>
  87. - <<ilm-shrink-action,Shrink>>
  88. - <<ilm-forcemerge-action,Force Merge>>
  89. * Cold
  90. - <<ilm-set-priority-action,Set Priority>>
  91. - <<ilm-unfollow-action,Unfollow>>
  92. - <<ilm-allocate-action,Allocate>>
  93. - <<ilm-freeze-action,Freeze>>
  94. * Delete
  95. - <<ilm-delete-action,Delete>>
  96. [[ilm-allocate-action]]
  97. ==== Allocate
  98. Phases allowed: warm, cold.
  99. The Allocate action allows you to specify which nodes are allowed to host the
  100. shards of the index and set the number of replicas.
  101. Behind the scenes, it is modifying the index settings
  102. for shard filtering and/or replica counts. When updating the number of replicas,
  103. configuring allocation rules is optional. When configuring allocation rules,
  104. setting number of replicas is optional. Although this action can be treated as
  105. two separate index settings updates, both can be configured at once.
  106. For more information about how {es} uses replicas for scaling, see
  107. <<scalability>>. See <<shard-allocation-filtering>> for more information about
  108. controlling where Elasticsearch allocates shards of a particular index.
  109. [[ilm-allocate-options]]
  110. .Allocate Options
  111. [options="header"]
  112. |======
  113. | Name | Required | Default | Description
  114. | `number_of_replicas` | no | - | The number of replicas to
  115. assign to the index
  116. | `include` | no | - | assigns an index to nodes
  117. having at least _one_ of the attributes
  118. | `exclude` | no | - | assigns an index to nodes having
  119. _none_ of the attributes
  120. | `require` | no | - | assigns an index to nodes having
  121. _all_ of the attributes
  122. |======
  123. If `number_of_replicas` is not configured, then at least one of `include`,
  124. `exclude`, and `require` is required. An empty Allocate Action with no configuration
  125. is invalid.
  126. ===== Example: Change number of replicas
  127. In this example, the index's number of replicas is changed to `2`, while allocation
  128. rules are unchanged.
  129. [source,js]
  130. --------------------------------------------------
  131. PUT _ilm/policy/my_policy
  132. {
  133. "policy": {
  134. "phases": {
  135. "warm": {
  136. "actions": {
  137. "allocate" : {
  138. "number_of_replicas" : 2
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. --------------------------------------------------
  146. // CONSOLE
  147. ===== Example: Assign index to node with specific "box_type" attribute
  148. This example assigns the index to nodes with `box_type` attribute of "hot" or "warm".
  149. [source,js]
  150. --------------------------------------------------
  151. PUT _ilm/policy/my_policy
  152. {
  153. "policy": {
  154. "phases": {
  155. "warm": {
  156. "actions": {
  157. "allocate" : {
  158. "include" : {
  159. "box_type": "hot,warm"
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. --------------------------------------------------
  168. // CONSOLE
  169. ===== Example: Assign index to a specific node and update replica settings
  170. This example updates the index to have one replica per shard and be allocated
  171. to nodes with a `box_type` attribute of "cold".
  172. [source,js]
  173. --------------------------------------------------
  174. PUT _ilm/policy/my_policy
  175. {
  176. "policy": {
  177. "phases": {
  178. "warm": {
  179. "actions": {
  180. "allocate" : {
  181. "number_of_replicas": 1,
  182. "require" : {
  183. "box_type": "cold"
  184. }
  185. }
  186. }
  187. }
  188. }
  189. }
  190. }
  191. --------------------------------------------------
  192. // CONSOLE
  193. [[ilm-delete-action]]
  194. ==== Delete
  195. Phases allowed: delete.
  196. The Delete Action does just that, it deletes the index.
  197. This action does not have any options associated with it.
  198. [source,js]
  199. --------------------------------------------------
  200. PUT _ilm/policy/my_policy
  201. {
  202. "policy": {
  203. "phases": {
  204. "delete": {
  205. "actions": {
  206. "delete" : { }
  207. }
  208. }
  209. }
  210. }
  211. }
  212. --------------------------------------------------
  213. // CONSOLE
  214. [[ilm-forcemerge-action]]
  215. ==== Force Merge
  216. Phases allowed: warm.
  217. NOTE: Index will be be made read-only when this action is run
  218. (see: <<dynamic-index-settings,index.blocks.write>>)
  219. The Force Merge Action <<indices-forcemerge,force merges>> the index into at
  220. most a specific number of <<indices-segments,segments>>.
  221. [[ilm-forcemerge-options]]
  222. .Force Merge Options
  223. [options="header"]
  224. |======
  225. | Name | Required | Default | Description
  226. | `max_num_segments` | yes | - | The number of
  227. segments to merge to.
  228. To fully merge the
  229. index, set it to `1`
  230. |======
  231. [source,js]
  232. --------------------------------------------------
  233. PUT _ilm/policy/my_policy
  234. {
  235. "policy": {
  236. "phases": {
  237. "warm": {
  238. "actions": {
  239. "forcemerge" : {
  240. "max_num_segments": 1
  241. }
  242. }
  243. }
  244. }
  245. }
  246. }
  247. --------------------------------------------------
  248. // CONSOLE
  249. [[ilm-freeze-action]]
  250. ==== Freeze
  251. Phases allowed: cold.
  252. This action will <<frozen-indices, freeze>> the index
  253. by calling the <<freeze-index-api, Freeze Index API>>.
  254. [source,js]
  255. --------------------------------------------------
  256. PUT _ilm/policy/my_policy
  257. {
  258. "policy": {
  259. "phases": {
  260. "cold": {
  261. "actions": {
  262. "freeze" : { }
  263. }
  264. }
  265. }
  266. }
  267. }
  268. --------------------------------------------------
  269. // CONSOLE
  270. [IMPORTANT]
  271. ================================
  272. Freezing an index will close the index and reopen it within the same API call.
  273. This causes primaries to not be allocated for a short amount of time and
  274. causes the cluster to go red until the primaries are allocated again.
  275. This limitation might be removed in the future.
  276. ================================
  277. [[ilm-readonly-action]]
  278. ==== Read-Only
  279. Phases allowed: warm.
  280. This action will set the index to be read-only
  281. (see: <<dynamic-index-settings,index.blocks.write>>)
  282. This action does not have any options associated with it.
  283. [source,js]
  284. --------------------------------------------------
  285. PUT _ilm/policy/my_policy
  286. {
  287. "policy": {
  288. "phases": {
  289. "warm": {
  290. "actions": {
  291. "readonly" : { }
  292. }
  293. }
  294. }
  295. }
  296. }
  297. --------------------------------------------------
  298. // CONSOLE
  299. [[ilm-rollover-action]]
  300. ==== Rollover
  301. Phases allowed: hot.
  302. [WARNING]
  303. index format must match pattern '^.*-\\d+$', for example (`logs-000001`).
  304. [WARNING]
  305. The managed index must set `index.lifecycle.rollover_alias` as the
  306. alias to rollover. The index must also be the write index for the alias.
  307. [IMPORTANT]
  308. If a policy using the Rollover action is used on a <<ccr-put-follow,follower
  309. index>>, policy execution will wait until the leader index rolls over (or has
  310. <<skipping-rollover, otherwise been marked as complete>>), then convert the
  311. follower index into a regular index as if <<ilm-unfollow-action,the Unfollow
  312. action>> had been used instead of rolling over.
  313. For example, if an index to be managed has an alias `my_data`. The managed
  314. index "my_index" must be the write index for the alias. For more information, read
  315. <<indices-rollover-is-write-index,Write Index Alias Behavior>>.
  316. [source,js]
  317. --------------------------------------------------
  318. PUT my_index
  319. {
  320. "settings": {
  321. "index.lifecycle.name": "my_policy",
  322. "index.lifecycle.rollover_alias": "my_data"
  323. },
  324. "aliases": {
  325. "my_data": {
  326. "is_write_index": true
  327. }
  328. }
  329. }
  330. --------------------------------------------------
  331. // CONSOLE
  332. The Rollover Action rolls an alias over to a new index when the
  333. existing index meets one of the rollover conditions.
  334. [[ilm-rollover-options]]
  335. .Rollover Options
  336. [options="header"]
  337. |======
  338. | Name | Required | Default | Description
  339. | `max_size` | no | - | max primary shard index storage size.
  340. See <<byte-units, Byte Units>>
  341. for formatting
  342. | `max_docs` | no | - | max number of documents an
  343. index is to contain before
  344. rolling over.
  345. | `max_age` | no | - | max time elapsed from index
  346. creation. See
  347. <<time-units, Time Units>>
  348. for formatting
  349. |======
  350. At least one of `max_size`, `max_docs`, `max_age` or any combinations of the
  351. three are required to be specified.
  352. ===== Example: Rollover when index is too large
  353. This example rolls the index over when it is at least 100 gigabytes.
  354. [source,js]
  355. --------------------------------------------------
  356. PUT _ilm/policy/my_policy
  357. {
  358. "policy": {
  359. "phases": {
  360. "hot": {
  361. "actions": {
  362. "rollover" : {
  363. "max_size": "100GB"
  364. }
  365. }
  366. }
  367. }
  368. }
  369. }
  370. --------------------------------------------------
  371. // CONSOLE
  372. ===== Example: Rollover when index has too many documents
  373. This example rolls the index over when it contains at least
  374. 100000000 documents.
  375. [source,js]
  376. --------------------------------------------------
  377. PUT _ilm/policy/my_policy
  378. {
  379. "policy": {
  380. "phases": {
  381. "hot": {
  382. "actions": {
  383. "rollover" : {
  384. "max_docs": 100000000
  385. }
  386. }
  387. }
  388. }
  389. }
  390. }
  391. --------------------------------------------------
  392. // CONSOLE
  393. ===== Example: Rollover when index is too old
  394. This example rolls the index over when it has been created at least
  395. 7 days ago.
  396. [source,js]
  397. --------------------------------------------------
  398. PUT _ilm/policy/my_policy
  399. {
  400. "policy": {
  401. "phases": {
  402. "hot": {
  403. "actions": {
  404. "rollover" : {
  405. "max_age": "7d"
  406. }
  407. }
  408. }
  409. }
  410. }
  411. }
  412. --------------------------------------------------
  413. // CONSOLE
  414. ===== Example: Rollover when index is too old or too large
  415. This example rolls the index over when it has been created at least
  416. 7 days ago or it is at least 100 gigabytes. In this case, the index will be
  417. rolled over when any of the conditions is met.
  418. [source,js]
  419. --------------------------------------------------
  420. PUT _ilm/policy/my_policy
  421. {
  422. "policy": {
  423. "phases": {
  424. "hot": {
  425. "actions": {
  426. "rollover" : {
  427. "max_age": "7d",
  428. "max_size": "100GB"
  429. }
  430. }
  431. }
  432. }
  433. }
  434. }
  435. --------------------------------------------------
  436. // CONSOLE
  437. ===== Example: Rollover condition stalls phase transition
  438. The Rollover action will only complete once one of its conditions is
  439. met. This means that any proceeding phases will be blocked until Rollover
  440. succeeds.
  441. [source,js]
  442. --------------------------------------------------
  443. PUT /_ilm/policy/rollover_policy
  444. {
  445. "policy": {
  446. "phases": {
  447. "hot": {
  448. "actions": {
  449. "rollover": {
  450. "max_size": "50G"
  451. }
  452. }
  453. },
  454. "delete": {
  455. "min_age": "1d",
  456. "actions": {
  457. "delete": {}
  458. }
  459. }
  460. }
  461. }
  462. }
  463. --------------------------------------------------
  464. // CONSOLE
  465. The above example illustrates a policy which attempts to delete an
  466. index one day after the index has been rolled over. It does not
  467. delete the index one day after it has been created.
  468. [[ilm-set-priority-action]]
  469. ==== Set Priority
  470. Phases allowed: hot, warm, cold.
  471. This action sets the <<recovery-prioritization, index priority>> on the index as
  472. soon as the policy enters the hot, warm, or cold phase. Indices with a higher
  473. priority will be recovered before indices with lower priorities following a node
  474. restart. Generally, indexes in the hot phase should have the highest value and
  475. indexes in the cold phase should have the lowest values. For example:
  476. 100 for the hot phase, 50 for the warm phase, and 0 for the cold phase.
  477. Indicies that don't set this value have an implicit default priority of 1.
  478. [[ilm-set-priority-options]]
  479. .Set Priority Options
  480. [options="header"]
  481. |======
  482. | Name | Required | Default | Description
  483. | `priority` | yes | - | The priority for the index. Must be 0 or greater.
  484. The value may also be set to null to remove the priority.
  485. |======
  486. [source,js]
  487. --------------------------------------------------
  488. PUT _ilm/policy/my_policy
  489. {
  490. "policy": {
  491. "phases": {
  492. "warm": {
  493. "actions": {
  494. "set_priority" : {
  495. "priority": 50
  496. }
  497. }
  498. }
  499. }
  500. }
  501. }
  502. --------------------------------------------------
  503. // CONSOLE
  504. [[ilm-shrink-action]]
  505. ==== Shrink
  506. NOTE: Index will be be made read-only when this action is run
  507. (see: <<dynamic-index-settings,index.blocks.write>>)
  508. [IMPORTANT]
  509. If a policy using the Shrink action is used on a <<ccr-put-follow,follower
  510. index>>, policy execution will wait until the leader index rolls over (or has
  511. <<skipping-rollover, otherwise been marked as complete>>), then convert the
  512. follower index into a regular index as if <<ilm-unfollow-action,the Unfollow
  513. action>> had been used before shrink is applied, as shrink cannot be safely
  514. applied to follower indices.
  515. This action shrinks an existing index into a new index with fewer primary
  516. shards. It calls the <<indices-shrink-index,Shrink API>> to shrink the index.
  517. Since allocating all the primary shards of the index to one node is a
  518. prerequisite, this action will first allocate the primary shards to a valid
  519. node. After shrinking, it will swap aliases pointing to the original index
  520. into the new shrunken index. The new index will also have a new name:
  521. "shrink-<origin-index-name>". So if the original index was called "logs",
  522. then the new index will be named "shrink-logs".
  523. [[ilm-shrink-options]]
  524. .Shrink Options
  525. [options="header"]
  526. |======
  527. | Name | Required | Default | Description
  528. | `number_of_shards` | yes | - | The number of shards
  529. to shrink to. must be
  530. a factor of the number
  531. of shards in the
  532. source index.
  533. |======
  534. [source,js]
  535. --------------------------------------------------
  536. PUT _ilm/policy/my_policy
  537. {
  538. "policy": {
  539. "phases": {
  540. "warm": {
  541. "actions": {
  542. "shrink" : {
  543. "number_of_shards": 1
  544. }
  545. }
  546. }
  547. }
  548. }
  549. }
  550. --------------------------------------------------
  551. // CONSOLE
  552. [[ilm-unfollow-action]]
  553. ==== Unfollow
  554. [IMPORTANT]
  555. This action may be used explicitly, as shown below, but this action is also run
  556. before <<ilm-rollover-action,the Rollover action>> and <<ilm-shrink-action,the
  557. Shrink action>> as described in the documentation for those actions.
  558. This action turns a {ref}/ccr-apis.html[ccr] follower index
  559. into a regular index. This can be desired when moving follower
  560. indices into the next phase. Also certain actions like shrink
  561. and rollover can then be performed safely on follower indices.
  562. This action will wait until is it safe to convert a follower index into a
  563. regular index. In particular, the following conditions must be met:
  564. * The leader index must have `index.lifecycle.indexing_complete` set to `true`.
  565. This happens automatically if the leader index is rolled over using
  566. <<ilm-rollover-action,the Rollover action>>, or may be set manually using
  567. the <<indices-update-settings,Index Settings API>>.
  568. * All operations performed on the leader index must have been replicated to the
  569. follower index. This ensures that no operations will be lost when the index is
  570. converted into a regular index.
  571. If the unfollow action encounters a follower index then
  572. the following operations will be performed on it:
  573. * Pauses indexing following for the follower index.
  574. * Closes the follower index.
  575. * Unfollows the follower index.
  576. * Opens the follower index (which is at this point is a regular index).
  577. The unfollow action does not have any options and
  578. if it encounters a non follower index, then the
  579. unfollow action leaves that index untouched and
  580. lets the next action operate on this index.
  581. [source,js]
  582. --------------------------------------------------
  583. PUT _ilm/policy/my_policy
  584. {
  585. "policy": {
  586. "phases": {
  587. "hot": {
  588. "actions": {
  589. "unfollow" : {}
  590. }
  591. }
  592. }
  593. }
  594. }
  595. --------------------------------------------------
  596. // CONSOLE
  597. === Full Policy
  598. With all of these actions, we can support complex management strategies for our
  599. indices. This policy will define an index that will start in the hot phase,
  600. rolling over every 50 GB or 7 days. After 30 days it enters the warm phase
  601. and increases the replicas to 2, force merges and shrinks. After 60 days
  602. it enters the cold phase and allocates to "cold" nodes, and after 90 days the
  603. index is deleted.
  604. [source,js]
  605. --------------------------------------------------
  606. PUT _ilm/policy/full_policy
  607. {
  608. "policy": {
  609. "phases": {
  610. "hot": {
  611. "actions": {
  612. "rollover": {
  613. "max_age": "7d",
  614. "max_size": "50G"
  615. }
  616. }
  617. },
  618. "warm": {
  619. "min_age": "30d",
  620. "actions": {
  621. "forcemerge": {
  622. "max_num_segments": 1
  623. },
  624. "shrink": {
  625. "number_of_shards": 1
  626. },
  627. "allocate": {
  628. "number_of_replicas": 2
  629. }
  630. }
  631. },
  632. "cold": {
  633. "min_age": "60d",
  634. "actions": {
  635. "allocate": {
  636. "require": {
  637. "type": "cold"
  638. }
  639. }
  640. }
  641. },
  642. "delete": {
  643. "min_age": "90d",
  644. "actions": {
  645. "delete": {}
  646. }
  647. }
  648. }
  649. }
  650. }
  651. --------------------------------------------------
  652. // CONSOLE