using-policies-rollover.asciidoc 6.1 KB

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