using-policies-rollover.asciidoc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. The rollover action takes the following parameters:
  20. .`rollover` Action Parameters
  21. |===
  22. |Name |Description
  23. |max_size |The maximum estimated size the index is allowed to grow
  24. to. Defaults tonull. Optional.
  25. |max_docs |The maximum number of document the index should
  26. contain. Defaults tonull. Optional.
  27. |max_age |The maximum age of the index. Defaults to `null`. Optional.
  28. |===
  29. These parameters are used to determine when the index is considered "full" and
  30. a rollover should be performed. Where multiple criteria are defined the
  31. rollover operation will be performed once any of the criteria are met.
  32. The following request defines a policy with a rollover action that triggers
  33. when the index size reaches 25GB. The old index is subsequently deleted after
  34. 30 days.
  35. NOTE: Once an index rolls over, {ilm} uses the timestamp of the rollover
  36. operation rather than the index creation time to evaluate when to move the
  37. index to the next phase. For indices that have rolled over, the `min_age`
  38. criteria specified for a phase is relative to the rollover time for indices. In
  39. this example, that means the index will be deleted 30 days after rollover, not
  40. 30 days from when the index was created.
  41. [source,js]
  42. --------------------------------------------------
  43. PUT /_ilm/policy/my_policy
  44. {
  45. "policy": {
  46. "phases": {
  47. "hot": {
  48. "actions": {
  49. "rollover": {
  50. "max_size": "25GB"
  51. }
  52. }
  53. },
  54. "delete": {
  55. "min_age": "30d",
  56. "actions": {
  57. "delete": {}
  58. }
  59. }
  60. }
  61. }
  62. }
  63. --------------------------------------------------
  64. // CONSOLE
  65. To use an {ilm} policy, you need to specify it in the index template used to
  66. create the indices. For example, the following template associates `my_policy`
  67. with indices created from the template `my_template`.
  68. [source,js]
  69. -----------------------
  70. PUT _template/my_template
  71. {
  72. "index_patterns": ["test-*"], <1>
  73. "settings": {
  74. "number_of_shards": 1,
  75. "number_of_replicas": 1,
  76. "index.lifecycle.name": "my_policy", <2>
  77. "index.lifecycle.rollover_alias": "test-alias" <3>
  78. }
  79. }
  80. -----------------------
  81. // CONSOLE
  82. <1> Template applies to all indices with the prefix test-
  83. <2> Associates my_policy with all indices created with this template
  84. <3> Rolls over the write alias test when the rollover action is triggered
  85. To be able to start using the policy for these `test-*` indexes we need to
  86. bootstrap the process by creating the first index.
  87. [source,js]
  88. -----------------------
  89. PUT test-000001 <1>
  90. {
  91. "aliases": {
  92. "test-alias":{
  93. "is_write_index": true <2>
  94. }
  95. }
  96. }
  97. -----------------------
  98. // CONSOLE
  99. <1> Creates the index called test-000001. The rollover action increments the
  100. suffix number for each subsequent index.
  101. <2> Designates this index as the write index for this alias.
  102. When the rollover is performed, the newly-created index is set as the write
  103. index for the rolled over alias. Documents sent to the alias are indexed into
  104. the new index, enabling indexing to continue uninterrupted.