policy-definitions.asciidoc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. beta[]
  2. [role="xpack"]
  3. [testenv="basic"]
  4. [[ilm-policy-definition]]
  5. == Policy Phases and Actions
  6. beta[]
  7. There are four stages in the index lifecycle, in the order
  8. they are executed.
  9. [options="header"]
  10. |======
  11. | Name | Description
  12. | `hot` | The index is actively being written to
  13. | `warm` | The index is generally not being written to, but is still queried
  14. | `cold` | The index is no longer being updated and is seldom queried. The
  15. information still needs to be searchable, but it's okay if those queries are
  16. slower.
  17. | `delete` | The index is no longer needed and can safely be deleted
  18. |======
  19. Each of these stages is called a "phase". A policy does not need to configure
  20. each phase for an index. For example, one policy may define only the hot
  21. phase and the delete phase, while another may define all four phases.
  22. === Timing
  23. beta[]
  24. Indices enter phases based on a phase's `min_age` parameter.
  25. The index will not enter the phase until the index's age is older than that
  26. of the `min_age`. The parameter is configured using a time
  27. duration format (see <<time-units, Time Units>>).
  28. `min_age` defaults to zero seconds `0s` for each phase if not specified.
  29. [source,js]
  30. --------------------------------------------------
  31. PUT _ilm/policy/my_policy
  32. {
  33. "policy": {
  34. "phases": {
  35. "warm": {
  36. "min_age": "1d",
  37. "actions": {
  38. "allocate": {
  39. "number_of_replicas": 1
  40. }
  41. }
  42. },
  43. "delete": {
  44. "min_age": "30d",
  45. "actions": {
  46. "delete": {}
  47. }
  48. }
  49. }
  50. }
  51. }
  52. --------------------------------------------------
  53. // CONSOLE
  54. The Above example configures a policy that moves the index into the warm
  55. phase after one day. Until then, the index is in a waiting state. After
  56. moving into the warm phase, it will wait until 30 days have elapsed before
  57. moving to the delete phase and deleting the index.
  58. `min_age` is usually the time elapsed from the time the index is created. If the
  59. index is rolled over, then `min_age` is the time elapsed from the time the index
  60. is rolled over. The intention here is to execute following phases and actions
  61. relative to when data was written last to a rolled over index.
  62. The previous phase's actions must complete before {ILM} will check `min_age` and
  63. transition into the next phase.
  64. === Actions
  65. beta[]
  66. The below list shows the actions which are available in each phase.
  67. * Hot
  68. - <<ilm-rollover-action,Rollover>>
  69. * Warm
  70. - <<ilm-allocate-action,Allocate>>
  71. - <<ilm-readonly-action,Read-Only>>
  72. - <<ilm-forcemerge-action,Force Merge>>
  73. - <<ilm-shrink-action,Shrink>>
  74. * Cold
  75. - <<ilm-allocate-action,Allocate>>
  76. * Delete
  77. - <<ilm-delete-action,Delete>>
  78. [[ilm-allocate-action]]
  79. ==== Allocate
  80. Phases allowed: warm, cold.
  81. The Allocate action allows you to specify which nodes are allowed to host the
  82. shards of the index and set the number of replicas.
  83. Behind the scenes, it is modifying the index settings
  84. for shard filtering and/or replica counts. When updating the number of replicas,
  85. configuring allocation rules is optional. When configuring allocation rules,
  86. setting number of replicas is optional. Although this action can be treated as
  87. two separate index settings updates, both can be configured at once.
  88. Read more about index replicas <<getting-started-shards-and-replicas,here>>.
  89. Read more about shard allocation filtering in
  90. the <<shard-allocation-filtering,Shard allocation filtering documentation>>.
  91. [[ilm-allocate-options]]
  92. .Allocate Options
  93. [options="header"]
  94. |======
  95. | Name | Required | Default | Description
  96. | `number_of_replicas` | no | - | The number of replicas to
  97. assign to the index
  98. | `include` | no | - | assigns an index to nodes
  99. having at least _one_ of the attributes
  100. | `exclude` | no | - | assigns an index to nodes having
  101. _none_ of the attributes
  102. | `require` | no | - | assigns an index to nodes having
  103. _all_ of the attributes
  104. |======
  105. If `number_of_replicas` is not configured, then at least one of `include`,
  106. `exclude`, and `require` is required. An empty Allocate Action with no configuration
  107. is invalid.
  108. ===== Example: Change number of replicas
  109. In this example, the index's number of replicas is changed to `2`, while allocation
  110. rules are unchanged.
  111. [source,js]
  112. --------------------------------------------------
  113. PUT _ilm/policy/my_policy
  114. {
  115. "policy": {
  116. "phases": {
  117. "warm": {
  118. "actions": {
  119. "allocate" : {
  120. "number_of_replicas" : 2
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. --------------------------------------------------
  128. // CONSOLE
  129. ===== Example: Assign index to node with specific "box_type" attribute
  130. This example assigns the index to nodes with `box_type` attribute of "hot" or "warm".
  131. [source,js]
  132. --------------------------------------------------
  133. PUT _ilm/policy/my_policy
  134. {
  135. "policy": {
  136. "phases": {
  137. "warm": {
  138. "actions": {
  139. "allocate" : {
  140. "include" : {
  141. "box_type": "hot,warm"
  142. }
  143. }
  144. }
  145. }
  146. }
  147. }
  148. }
  149. --------------------------------------------------
  150. // CONSOLE
  151. ===== Example: Assign index to a specific node and update replica settings
  152. This example updates the index to have one replica per shard and be allocated
  153. to nodes with a `box_type` attribute of "cold".
  154. [source,js]
  155. --------------------------------------------------
  156. PUT _ilm/policy/my_policy
  157. {
  158. "policy": {
  159. "phases": {
  160. "warm": {
  161. "actions": {
  162. "allocate" : {
  163. "number_of_replicas": 1,
  164. "require" : {
  165. "box_type": "cold"
  166. }
  167. }
  168. }
  169. }
  170. }
  171. }
  172. }
  173. --------------------------------------------------
  174. // CONSOLE
  175. [[ilm-delete-action]]
  176. ==== Delete
  177. Phases allowed: delete.
  178. The Delete Action does just that, it deletes the index.
  179. This action does not have any options associated with it.
  180. [source,js]
  181. --------------------------------------------------
  182. PUT _ilm/policy/my_policy
  183. {
  184. "policy": {
  185. "phases": {
  186. "delete": {
  187. "actions": {
  188. "delete" : { }
  189. }
  190. }
  191. }
  192. }
  193. }
  194. --------------------------------------------------
  195. // CONSOLE
  196. [[ilm-forcemerge-action]]
  197. ==== Force Merge
  198. Phases allowed: warm.
  199. NOTE: Index will be be made read-only when this action is run
  200. (see: <<dynamic-index-settings,index.blocks.write>>)
  201. The Force Merge Action <<indices-forcemerge,force merges>> the index into at
  202. most a specific number of <<indices-segments,segments>>.
  203. [[ilm-forcemerge-options]]
  204. .Force Merge Options
  205. [options="header"]
  206. |======
  207. | Name | Required | Default | Description
  208. | `max_num_segments` | yes | - | The number of
  209. segments to merge to.
  210. To fully merge the
  211. index, set it to `1`
  212. |======
  213. [source,js]
  214. --------------------------------------------------
  215. PUT _ilm/policy/my_policy
  216. {
  217. "policy": {
  218. "phases": {
  219. "warm": {
  220. "actions": {
  221. "forcemerge" : {
  222. "max_num_segments": 1
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. --------------------------------------------------
  230. // CONSOLE
  231. [[ilm-readonly-action]]
  232. ==== Read-Only
  233. Phases allowed: warm.
  234. This action will set the index to be read-only
  235. (see: <<dynamic-index-settings,index.blocks.write>>)
  236. This action does not have any options associated with it.
  237. [source,js]
  238. --------------------------------------------------
  239. PUT _ilm/policy/my_policy
  240. {
  241. "policy": {
  242. "phases": {
  243. "warm": {
  244. "actions": {
  245. "readonly" : { }
  246. }
  247. }
  248. }
  249. }
  250. }
  251. --------------------------------------------------
  252. // CONSOLE
  253. [[ilm-rollover-action]]
  254. ==== Rollover
  255. Phases allowed: hot.
  256. [WARNING]
  257. index format must match pattern '^.*-\\d+$', for example (`logs-000001`).
  258. [WARNING]
  259. The managed index must set `index.lifecycle.rollover_alias` as the
  260. alias to rollover. The index must also be the write index for the alias.
  261. For example, if an index to be managed has an alias `my_data`. The managed
  262. index "my_index" must be the write index for the alias. For more information, read
  263. <<indices-rollover-is-write-index,Write Index Alias Behavior>>.
  264. [source,js]
  265. --------------------------------------------------
  266. PUT my_index
  267. {
  268. "settings": {
  269. "index.lifecycle.name": "my_policy",
  270. "index.lifecycle.rollover_alias": "my_data"
  271. },
  272. "aliases": {
  273. "my_data": {
  274. "is_write_index": true
  275. }
  276. }
  277. }
  278. --------------------------------------------------
  279. // CONSOLE
  280. The Rollover Action rolls an alias over to a new index when the
  281. existing index meets one of the rollover conditions.
  282. [[ilm-rollover-options]]
  283. .Rollover Options
  284. [options="header"]
  285. |======
  286. | Name | Required | Default | Description
  287. | `max_size` | no | - | max index storage size.
  288. See <<byte-units, Byte Units>>
  289. for formatting
  290. | `max_docs` | no | - | max number of documents an
  291. index is to contain before
  292. rolling over.
  293. | `max_age` | no | - | max time elapsed from index
  294. creation. See
  295. <<time-units, Time Units>>
  296. for formatting
  297. |======
  298. At least one of `max_size`, `max_docs`, `max_age` or any combinations of the
  299. three are required to be specified.
  300. ===== Example: Rollover when index is too large
  301. This example rolls the index over when it is at least 100 gigabytes.
  302. [source,js]
  303. --------------------------------------------------
  304. PUT _ilm/policy/my_policy
  305. {
  306. "policy": {
  307. "phases": {
  308. "hot": {
  309. "actions": {
  310. "rollover" : {
  311. "max_size": "100GB"
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. --------------------------------------------------
  319. // CONSOLE
  320. ===== Example: Rollover when index has too many documents
  321. This example rolls the index over when it contains at least
  322. 1000000 documents.
  323. [source,js]
  324. --------------------------------------------------
  325. PUT _ilm/policy/my_policy
  326. {
  327. "policy": {
  328. "phases": {
  329. "hot": {
  330. "actions": {
  331. "rollover" : {
  332. "max_docs": 1000000
  333. }
  334. }
  335. }
  336. }
  337. }
  338. }
  339. --------------------------------------------------
  340. // CONSOLE
  341. ===== Example: Rollover when index is too old
  342. This example rolls the index over when it has been created at least
  343. 7 days ago.
  344. [source,js]
  345. --------------------------------------------------
  346. PUT _ilm/policy/my_policy
  347. {
  348. "policy": {
  349. "phases": {
  350. "hot": {
  351. "actions": {
  352. "rollover" : {
  353. "max_age": "7d"
  354. }
  355. }
  356. }
  357. }
  358. }
  359. }
  360. --------------------------------------------------
  361. // CONSOLE
  362. ===== Example: Rollover when index is too old or too large
  363. This example rolls the index over when it has been created at least
  364. 7 days ago or it is at least 100 gigabytes. In this case, the index will be
  365. rolled over when any of the conditions is met.
  366. [source,js]
  367. --------------------------------------------------
  368. PUT _ilm/policy/my_policy
  369. {
  370. "policy": {
  371. "phases": {
  372. "hot": {
  373. "actions": {
  374. "rollover" : {
  375. "max_age": "7d",
  376. "max_size": "100GB"
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }
  383. --------------------------------------------------
  384. // CONSOLE
  385. ===== Example: Rollover condition stalls phase transition
  386. The Rollover action will only complete once one of its conditions is
  387. met. This means that any proceeding phases will be blocked until Rollover
  388. succeeds.
  389. [source,js]
  390. --------------------------------------------------
  391. PUT /_ilm/policy/rollover_policy
  392. {
  393. "policy": {
  394. "phases": {
  395. "hot": {
  396. "actions": {
  397. "rollover": {
  398. "max_size": "50G"
  399. }
  400. }
  401. },
  402. "delete": {
  403. "min_age": "1d",
  404. "actions": {
  405. "delete": {}
  406. }
  407. }
  408. }
  409. }
  410. }
  411. --------------------------------------------------
  412. // CONSOLE
  413. The above example illustrates a policy which attempts to delete an
  414. index one day after the index has been rolled over. It does not
  415. delete the index one day after it has been created.
  416. [[ilm-shrink-action]]
  417. ==== Shrink
  418. NOTE: Index will be be made read-only when this action is run
  419. (see: <<dynamic-index-settings,index.blocks.write>>)
  420. This action shrinks an existing index into a new index with fewer primary
  421. shards. It calls the <<indices-shrink-index,Shrink API>> to shrink the index.
  422. Since allocating all the primary shards of the index to one node is a
  423. prerequisite, this action will first allocate the primary shards to a valid
  424. node. After shrinking, it will swap aliases pointing to the original index
  425. into the new shrunken index. The new index will also have a new name:
  426. "shrink-<origin-index-name>". So if the original index was called "logs",
  427. then the new index will be named "shrink-logs".
  428. [[ilm-shrink-options]]
  429. .Shrink Options
  430. [options="header"]
  431. |======
  432. | Name | Required | Default | Description
  433. | `number_of_shards` | yes | - | The number of shards
  434. to shrink to. must be
  435. a factor of the number
  436. of shards in the
  437. source index.
  438. |======
  439. [source,js]
  440. --------------------------------------------------
  441. PUT _ilm/policy/my_policy
  442. {
  443. "policy": {
  444. "phases": {
  445. "warm": {
  446. "actions": {
  447. "shrink" : {
  448. "number_of_shards": 1
  449. }
  450. }
  451. }
  452. }
  453. }
  454. }
  455. --------------------------------------------------
  456. // CONSOLE
  457. === Full Policy
  458. beta[]
  459. With all of these actions, we can support complex management strategies for our
  460. indices. This policy will define an index that will start in the hot phase,
  461. rolling over every 20g or 7 days. After 30 days it enters the warm phase
  462. and increases the replicas to 2, force merges and shrinks. After 60 days
  463. it enters the cold phase and allocates to "cold" nodes, and after 90 days the
  464. index is deleted.
  465. [source,js]
  466. --------------------------------------------------
  467. PUT _ilm/policy/full_policy
  468. {
  469. "policy": {
  470. "phases": {
  471. "hot": {
  472. "actions": {
  473. "rollover": {
  474. "max_age": "7d",
  475. "max_size": "20G"
  476. }
  477. }
  478. },
  479. "warm": {
  480. "min_age": "30d",
  481. "actions": {
  482. "forcemerge": {
  483. "max_num_segments": 1
  484. },
  485. "shrink": {
  486. "number_of_shards": 1
  487. },
  488. "allocate": {
  489. "number_of_replicas": 2
  490. }
  491. }
  492. },
  493. "cold": {
  494. "min_age": "60d",
  495. "actions": {
  496. "allocate": {
  497. "require": {
  498. "type": "cold"
  499. }
  500. }
  501. }
  502. },
  503. "delete": {
  504. "min_age": "90d",
  505. "actions": {
  506. "delete": {}
  507. }
  508. }
  509. }
  510. }
  511. }
  512. --------------------------------------------------
  513. // CONSOLE