using-policies-rollover.asciidoc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[using-policies-rollover]]
  4. == Roll over automatically
  5. The rollover action enables you to automatically roll over to a new index based
  6. on the index size, document count, or age. When a rollover is triggered, a new
  7. index is created, the write alias is updated to point to the new index, and all
  8. subsequent updates are written to the new index.
  9. Rolling over to a new index based on size, document count, or age is preferable
  10. to time-based rollovers. Rolling over at an arbitrary time often results in
  11. many small indices, which can have a negative impact on performance and
  12. resource usage.
  13. You control when the rollover action is triggered by specifying one or more
  14. rollover parameters. The rollover is performed once any of the criteria are
  15. met. Because the criteria are checked periodically, the index might grow
  16. slightly beyond the specified threshold. To control how often the criteria are
  17. checked, specify the `indices.lifecycle.poll_interval` cluster setting.
  18. IMPORTANT: New indices created via rollover will not automatically inherit the
  19. policy used by the old index, and will not use any policy by default. Therefore,
  20. it is highly recommended to apply the policy via
  21. <<applying-policy-to-template,index template>>, including a Rollover alias
  22. setting, for your indices which specifies the policy you wish to use for each
  23. new index.
  24. The rollover action takes the following parameters:
  25. [[rollover-action-params]]
  26. .`rollover` Action Parameters
  27. [options="header"]
  28. |===
  29. |Name |Description
  30. |max_size |The maximum estimated size the primary shard of the index is allowed
  31. to grow to. Defaults to `null`. Optional.
  32. |max_docs |The maximum number of document the index should
  33. contain. Defaults to `null`. Optional.
  34. |max_age |The maximum age of the index. Defaults to `null`. Optional.
  35. |===
  36. These parameters are used to determine when the index is considered "full" and
  37. a rollover should be performed. Where multiple criteria are defined the
  38. rollover operation will be performed once any of the criteria are met.
  39. The following request defines a policy with a rollover action that triggers
  40. when the index size reaches 25GB. The old index is subsequently deleted after
  41. 30 days.
  42. NOTE: Once an index rolls over, {ilm} uses the timestamp of the rollover
  43. operation rather than the index creation time to evaluate when to move the
  44. index to the next phase. For indices that have rolled over, the `min_age`
  45. criteria specified for a phase is relative to the rollover time for indices. In
  46. this example, that means the index will be deleted 30 days after rollover, not
  47. 30 days from when the index was created.
  48. [source,console]
  49. --------------------------------------------------
  50. PUT /_ilm/policy/my_policy
  51. {
  52. "policy": {
  53. "phases": {
  54. "hot": {
  55. "actions": {
  56. "rollover": {
  57. "max_size": "25GB"
  58. }
  59. }
  60. },
  61. "delete": {
  62. "min_age": "30d",
  63. "actions": {
  64. "delete": {}
  65. }
  66. }
  67. }
  68. }
  69. }
  70. --------------------------------------------------
  71. To use an {ilm} policy, you need to specify it in the index template used to
  72. create the indices. For example, the following template associates `my_policy`
  73. with indices created from the template `my_template`.
  74. [source,console]
  75. -----------------------
  76. PUT _template/my_template
  77. {
  78. "index_patterns": ["test-*"], <1>
  79. "settings": {
  80. "number_of_shards": 1,
  81. "number_of_replicas": 1,
  82. "index.lifecycle.name": "my_policy", <2>
  83. "index.lifecycle.rollover_alias": "test-alias" <3>
  84. }
  85. }
  86. -----------------------
  87. <1> Template applies to all indices with the prefix test-
  88. <2> Associates my_policy with all indices created with this template
  89. <3> Rolls over the write alias test when the rollover action is triggered
  90. //////////////////////////
  91. [source,console]
  92. --------------------------------------------------
  93. DELETE /_template/my_template
  94. --------------------------------------------------
  95. // TEST[continued]
  96. //////////////////////////
  97. To be able to start using the policy for these `test-*` indexes we need to
  98. bootstrap the process by creating the first index.
  99. [source,console]
  100. -----------------------
  101. PUT test-000001 <1>
  102. {
  103. "aliases": {
  104. "test-alias":{
  105. "is_write_index": true <2>
  106. }
  107. }
  108. }
  109. -----------------------
  110. <1> Creates the index called test-000001. The rollover action increments the
  111. suffix number for each subsequent index.
  112. <2> Designates this index as the write index for this alias.
  113. When the rollover is performed, the newly-created index is set as the write
  114. index for the rolled over alias. Documents sent to the alias are indexed into
  115. the new index, enabling indexing to continue uninterrupted.
  116. [[skipping-rollover]]
  117. === Skipping Rollover
  118. The `index.lifecycle.indexing_complete` setting indicates to {ilm} whether this
  119. index has already been rolled over. If it is set to `true`, that indicates that
  120. this index has already been rolled over and does not need to be rolled over
  121. again. Therefore, {ilm} will skip any Rollover Action configured in the
  122. associated lifecycle policy for this index. This is useful if you need to make
  123. an exception to your normal Lifecycle Policy and switching the alias to a
  124. different index by hand, but do not want to remove the index from {ilm}
  125. completely.
  126. This setting is set to `true` automatically by ILM upon the successful
  127. completion of a Rollover Action. However, it will be removed if
  128. <<ilm-remove-policy,the policy is removed>> from the index.
  129. IMPORTANT: If `index.lifecycle.indexing_complete` is set to `true` on an index,
  130. it will not be rolled over by {ilm}, but {ilm} will verify that this index is no
  131. longer the write index for the alias specified by
  132. `index.lifecycle.rollover_alias`. If that setting is missing, or if the index is
  133. still the write index for that alias, this index will be moved to the
  134. <<index-lifecycle-error-handling,error step>>.
  135. For example, if you wish to change the name of new indices while retaining
  136. previous data in accordance with your configured policy, you can create the
  137. template for the new index name pattern and the first index with the new name
  138. manually, change the write index of the alias using the <<indices-aliases, Index
  139. Aliases API>>, and set `index.lifecycle.indexing_complete` to `true` on the old
  140. index to indicate that it does not need to be rolled over. This way, {ilm} will
  141. continue to manage the old index in accordance with its existing policy, as well
  142. as the new one, with no interruption.