policy-definitions.asciidoc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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`
  60. and transition into the next phase.
  61. === Phase Execution
  62. The current phase definition, of an index's policy being executed, is stored
  63. in the index's metadata. The phase and its actions are compiled into a series
  64. of discrete steps that are executed sequentially. Since some {ilm-init} actions
  65. are more complex and involve multiple operations against an index, each of these
  66. operations are done in isolation in a unit called a "step". The
  67. <<ilm-explain-lifecycle,Explain Lifecycle API>> exposes this information to us
  68. to see which step our index is either to execute next, or is currently
  69. executing.
  70. === Actions
  71. The below list shows the actions which are available in each phase.
  72. * Hot
  73. - <<ilm-rollover-action,Rollover>>
  74. * Warm
  75. - <<ilm-allocate-action,Allocate>>
  76. - <<ilm-readonly-action,Read-Only>>
  77. - <<ilm-forcemerge-action,Force Merge>>
  78. - <<ilm-shrink-action,Shrink>>
  79. * Cold
  80. - <<ilm-allocate-action,Allocate>>
  81. * Delete
  82. - <<ilm-delete-action,Delete>>
  83. [[ilm-allocate-action]]
  84. ==== Allocate
  85. Phases allowed: warm, cold.
  86. The Allocate action allows you to specify which nodes are allowed to host the
  87. shards of the index and set the number of replicas.
  88. Behind the scenes, it is modifying the index settings
  89. for shard filtering and/or replica counts. When updating the number of replicas,
  90. configuring allocation rules is optional. When configuring allocation rules,
  91. setting number of replicas is optional. Although this action can be treated as
  92. two separate index settings updates, both can be configured at once.
  93. Read more about index replicas <<getting-started-shards-and-replicas,here>>.
  94. Read more about shard allocation filtering in
  95. the <<shard-allocation-filtering,Shard allocation filtering documentation>>.
  96. [[ilm-allocate-options]]
  97. .Allocate Options
  98. [options="header"]
  99. |======
  100. | Name | Required | Default | Description
  101. | `number_of_replicas` | no | - | The number of replicas to
  102. assign to the index
  103. | `include` | no | - | assigns an index to nodes
  104. having at least _one_ of the attributes
  105. | `exclude` | no | - | assigns an index to nodes having
  106. _none_ of the attributes
  107. | `require` | no | - | assigns an index to nodes having
  108. _all_ of the attributes
  109. |======
  110. If `number_of_replicas` is not configured, then at least one of `include`,
  111. `exclude`, and `require` is required. An empty Allocate Action with no configuration
  112. is invalid.
  113. ===== Example: Change number of replicas
  114. In this example, the index's number of replicas is changed to `2`, while allocation
  115. rules are unchanged.
  116. [source,js]
  117. --------------------------------------------------
  118. PUT _ilm/policy/my_policy
  119. {
  120. "policy": {
  121. "phases": {
  122. "warm": {
  123. "actions": {
  124. "allocate" : {
  125. "number_of_replicas" : 2
  126. }
  127. }
  128. }
  129. }
  130. }
  131. }
  132. --------------------------------------------------
  133. // CONSOLE
  134. ===== Example: Assign index to node with specific "box_type" attribute
  135. This example assigns the index to nodes with `box_type` attribute of "hot" or "warm".
  136. [source,js]
  137. --------------------------------------------------
  138. PUT _ilm/policy/my_policy
  139. {
  140. "policy": {
  141. "phases": {
  142. "warm": {
  143. "actions": {
  144. "allocate" : {
  145. "include" : {
  146. "box_type": "hot,warm"
  147. }
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }
  154. --------------------------------------------------
  155. // CONSOLE
  156. ===== Example: Assign index to a specific node and update replica settings
  157. This example updates the index to have one replica per shard and be allocated
  158. to nodes with a `box_type` attribute of "cold".
  159. [source,js]
  160. --------------------------------------------------
  161. PUT _ilm/policy/my_policy
  162. {
  163. "policy": {
  164. "phases": {
  165. "warm": {
  166. "actions": {
  167. "allocate" : {
  168. "number_of_replicas": 1,
  169. "require" : {
  170. "box_type": "cold"
  171. }
  172. }
  173. }
  174. }
  175. }
  176. }
  177. }
  178. --------------------------------------------------
  179. // CONSOLE
  180. [[ilm-delete-action]]
  181. ==== Delete
  182. Phases allowed: delete.
  183. The Delete Action does just that, it deletes the index.
  184. This action does not have any options associated with it.
  185. [source,js]
  186. --------------------------------------------------
  187. PUT _ilm/policy/my_policy
  188. {
  189. "policy": {
  190. "phases": {
  191. "delete": {
  192. "actions": {
  193. "delete" : { }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. --------------------------------------------------
  200. // CONSOLE
  201. [[ilm-forcemerge-action]]
  202. ==== Force Merge
  203. Phases allowed: warm.
  204. NOTE: Index will be be made read-only when this action is run
  205. (see: <<dynamic-index-settings,index.blocks.write>>)
  206. The Force Merge Action <<indices-forcemerge,force merges>> the index into at
  207. most a specific number of <<indices-segments,segments>>.
  208. [[ilm-forcemerge-options]]
  209. .Force Merge Options
  210. [options="header"]
  211. |======
  212. | Name | Required | Default | Description
  213. | `max_num_segments` | yes | - | The number of
  214. segments to merge to.
  215. To fully merge the
  216. index, set it to `1`
  217. |======
  218. [source,js]
  219. --------------------------------------------------
  220. PUT _ilm/policy/my_policy
  221. {
  222. "policy": {
  223. "phases": {
  224. "warm": {
  225. "actions": {
  226. "forcemerge" : {
  227. "max_num_segments": 1
  228. }
  229. }
  230. }
  231. }
  232. }
  233. }
  234. --------------------------------------------------
  235. // CONSOLE
  236. [[ilm-freeze-action]]
  237. ==== Freeze
  238. Phases allowed: cold.
  239. This action will <<frozen-indices, freeze>> the index
  240. by calling the <<freeze-index-api, Freeze Index API>>.
  241. [source,js]
  242. --------------------------------------------------
  243. PUT _ilm/policy/my_policy
  244. {
  245. "policy": {
  246. "phases": {
  247. "cold": {
  248. "actions": {
  249. "freeze" : { }
  250. }
  251. }
  252. }
  253. }
  254. }
  255. --------------------------------------------------
  256. // CONSOLE
  257. [IMPORTANT]
  258. ================================
  259. Freezing an index will close the index and reopen it within the same API call.
  260. This causes primaries to not be allocated for a short amount of time and
  261. causes the cluster to go red until the primaries are allocated again.
  262. This limitation might be removed in the future.
  263. ================================
  264. [[ilm-readonly-action]]
  265. ==== Read-Only
  266. Phases allowed: warm.
  267. This action will set the index to be read-only
  268. (see: <<dynamic-index-settings,index.blocks.write>>)
  269. This action does not have any options associated with it.
  270. [source,js]
  271. --------------------------------------------------
  272. PUT _ilm/policy/my_policy
  273. {
  274. "policy": {
  275. "phases": {
  276. "warm": {
  277. "actions": {
  278. "readonly" : { }
  279. }
  280. }
  281. }
  282. }
  283. }
  284. --------------------------------------------------
  285. // CONSOLE
  286. [[ilm-rollover-action]]
  287. ==== Rollover
  288. Phases allowed: hot.
  289. [WARNING]
  290. index format must match pattern '^.*-\\d+$', for example (`logs-000001`).
  291. [WARNING]
  292. The managed index must set `index.lifecycle.rollover_alias` as the
  293. alias to rollover. The index must also be the write index for the alias.
  294. For example, if an index to be managed has an alias `my_data`. The managed
  295. index "my_index" must be the write index for the alias. For more information, read
  296. <<indices-rollover-is-write-index,Write Index Alias Behavior>>.
  297. [source,js]
  298. --------------------------------------------------
  299. PUT my_index
  300. {
  301. "settings": {
  302. "index.lifecycle.name": "my_policy",
  303. "index.lifecycle.rollover_alias": "my_data"
  304. },
  305. "aliases": {
  306. "my_data": {
  307. "is_write_index": true
  308. }
  309. }
  310. }
  311. --------------------------------------------------
  312. // CONSOLE
  313. The Rollover Action rolls an alias over to a new index when the
  314. existing index meets one of the rollover conditions.
  315. [[ilm-rollover-options]]
  316. .Rollover Options
  317. [options="header"]
  318. |======
  319. | Name | Required | Default | Description
  320. | `max_size` | no | - | max index storage size.
  321. See <<byte-units, Byte Units>>
  322. for formatting
  323. | `max_docs` | no | - | max number of documents an
  324. index is to contain before
  325. rolling over.
  326. | `max_age` | no | - | max time elapsed from index
  327. creation. See
  328. <<time-units, Time Units>>
  329. for formatting
  330. |======
  331. At least one of `max_size`, `max_docs`, `max_age` or any combinations of the
  332. three are required to be specified.
  333. ===== Example: Rollover when index is too large
  334. This example rolls the index over when it is at least 100 gigabytes.
  335. [source,js]
  336. --------------------------------------------------
  337. PUT _ilm/policy/my_policy
  338. {
  339. "policy": {
  340. "phases": {
  341. "hot": {
  342. "actions": {
  343. "rollover" : {
  344. "max_size": "100GB"
  345. }
  346. }
  347. }
  348. }
  349. }
  350. }
  351. --------------------------------------------------
  352. // CONSOLE
  353. ===== Example: Rollover when index has too many documents
  354. This example rolls the index over when it contains at least
  355. 100000000 documents.
  356. [source,js]
  357. --------------------------------------------------
  358. PUT _ilm/policy/my_policy
  359. {
  360. "policy": {
  361. "phases": {
  362. "hot": {
  363. "actions": {
  364. "rollover" : {
  365. "max_docs": 100000000
  366. }
  367. }
  368. }
  369. }
  370. }
  371. }
  372. --------------------------------------------------
  373. // CONSOLE
  374. ===== Example: Rollover when index is too old
  375. This example rolls the index over when it has been created at least
  376. 7 days ago.
  377. [source,js]
  378. --------------------------------------------------
  379. PUT _ilm/policy/my_policy
  380. {
  381. "policy": {
  382. "phases": {
  383. "hot": {
  384. "actions": {
  385. "rollover" : {
  386. "max_age": "7d"
  387. }
  388. }
  389. }
  390. }
  391. }
  392. }
  393. --------------------------------------------------
  394. // CONSOLE
  395. ===== Example: Rollover when index is too old or too large
  396. This example rolls the index over when it has been created at least
  397. 7 days ago or it is at least 100 gigabytes. In this case, the index will be
  398. rolled over when any of the conditions is met.
  399. [source,js]
  400. --------------------------------------------------
  401. PUT _ilm/policy/my_policy
  402. {
  403. "policy": {
  404. "phases": {
  405. "hot": {
  406. "actions": {
  407. "rollover" : {
  408. "max_age": "7d",
  409. "max_size": "100GB"
  410. }
  411. }
  412. }
  413. }
  414. }
  415. }
  416. --------------------------------------------------
  417. // CONSOLE
  418. ===== Example: Rollover condition stalls phase transition
  419. The Rollover action will only complete once one of its conditions is
  420. met. This means that any proceeding phases will be blocked until Rollover
  421. succeeds.
  422. [source,js]
  423. --------------------------------------------------
  424. PUT /_ilm/policy/rollover_policy
  425. {
  426. "policy": {
  427. "phases": {
  428. "hot": {
  429. "actions": {
  430. "rollover": {
  431. "max_size": "50G"
  432. }
  433. }
  434. },
  435. "delete": {
  436. "min_age": "1d",
  437. "actions": {
  438. "delete": {}
  439. }
  440. }
  441. }
  442. }
  443. }
  444. --------------------------------------------------
  445. // CONSOLE
  446. The above example illustrates a policy which attempts to delete an
  447. index one day after the index has been rolled over. It does not
  448. delete the index one day after it has been created.
  449. [[ilm-shrink-action]]
  450. ==== Shrink
  451. NOTE: Index will be be made read-only when this action is run
  452. (see: <<dynamic-index-settings,index.blocks.write>>)
  453. This action shrinks an existing index into a new index with fewer primary
  454. shards. It calls the <<indices-shrink-index,Shrink API>> to shrink the index.
  455. Since allocating all the primary shards of the index to one node is a
  456. prerequisite, this action will first allocate the primary shards to a valid
  457. node. After shrinking, it will swap aliases pointing to the original index
  458. into the new shrunken index. The new index will also have a new name:
  459. "shrink-<origin-index-name>". So if the original index was called "logs",
  460. then the new index will be named "shrink-logs".
  461. [[ilm-shrink-options]]
  462. .Shrink Options
  463. [options="header"]
  464. |======
  465. | Name | Required | Default | Description
  466. | `number_of_shards` | yes | - | The number of shards
  467. to shrink to. must be
  468. a factor of the number
  469. of shards in the
  470. source index.
  471. |======
  472. [source,js]
  473. --------------------------------------------------
  474. PUT _ilm/policy/my_policy
  475. {
  476. "policy": {
  477. "phases": {
  478. "warm": {
  479. "actions": {
  480. "shrink" : {
  481. "number_of_shards": 1
  482. }
  483. }
  484. }
  485. }
  486. }
  487. }
  488. --------------------------------------------------
  489. // CONSOLE
  490. === Full Policy
  491. With all of these actions, we can support complex management strategies for our
  492. indices. This policy will define an index that will start in the hot phase,
  493. rolling over every 50 GB or 7 days. After 30 days it enters the warm phase
  494. and increases the replicas to 2, force merges and shrinks. After 60 days
  495. it enters the cold phase and allocates to "cold" nodes, and after 90 days the
  496. index is deleted.
  497. [source,js]
  498. --------------------------------------------------
  499. PUT _ilm/policy/full_policy
  500. {
  501. "policy": {
  502. "phases": {
  503. "hot": {
  504. "actions": {
  505. "rollover": {
  506. "max_age": "7d",
  507. "max_size": "50G"
  508. }
  509. }
  510. },
  511. "warm": {
  512. "min_age": "30d",
  513. "actions": {
  514. "forcemerge": {
  515. "max_num_segments": 1
  516. },
  517. "shrink": {
  518. "number_of_shards": 1
  519. },
  520. "allocate": {
  521. "number_of_replicas": 2
  522. }
  523. }
  524. },
  525. "cold": {
  526. "min_age": "60d",
  527. "actions": {
  528. "allocate": {
  529. "require": {
  530. "type": "cold"
  531. }
  532. }
  533. }
  534. },
  535. "delete": {
  536. "min_age": "90d",
  537. "actions": {
  538. "delete": {}
  539. }
  540. }
  541. }
  542. }
  543. }
  544. --------------------------------------------------
  545. // CONSOLE