policy-definitions.asciidoc 21 KB

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