using-policies-rollover.asciidoc 5.3 KB

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