example-index-lifecycle-policy.asciidoc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. [role="xpack"]
  2. [[example-using-index-lifecycle-policy]]
  3. === Tutorial: Manage {filebeat} time-based indices
  4. ++++
  5. <titleabbrev>Manage {filebeat} time-based indices</titleabbrev>
  6. ++++
  7. With {ilm} ({ilm-init}), you can create policies that perform actions automatically
  8. on indices as they age and grow. {ilm-init} policies help you to manage
  9. performance, resilience, and retention of your data during its lifecycle. This tutorial shows
  10. you how to use {kib}’s *Index Lifecycle Policies* to modify and create {ilm-init}
  11. policies. You can learn more about all of the actions, benefits, and lifecycle
  12. phases in the <<overview-index-lifecycle-management, {ilm-init} overview>>.
  13. [discrete]
  14. [[example-using-index-lifecycle-policy-scenario]]
  15. ==== Scenario
  16. You’re tasked with sending syslog files to an {es} cluster. This
  17. log data has the following data retention guidelines:
  18. * Keep logs on hot data nodes for 30 days
  19. * Roll over to a new index if the size reaches 50GB
  20. * After 30 days:
  21. ** Move the logs to warm data nodes
  22. ** Set <<glossary-replica-shard, replica shards>> to 1
  23. ** <<indices-forcemerge, Force merge>> multiple index segments to free up the space used by deleted documents
  24. * Delete logs after 90 days
  25. [discrete]
  26. [[example-using-index-lifecycle-policy-prerequisites]]
  27. ==== Prerequisites
  28. To complete this tutorial, you'll need:
  29. * An {es} cluster with hot and warm nodes configured for shard allocation
  30. awareness.
  31. ** {ess}:
  32. Choose the Elastic Stack and then the {cloud}/ec-getting-started-profiles.html#ec-getting-started-profiles-hot-warm[hot-warm architecture] hardware profile.
  33. ** Self-managed cluster:
  34. Add node attributes as described for {ref}/shard-allocation-filtering.html[shard allocation filtering].
  35. +
  36. For example, you can set this in your `elasticsearch.yml` for each data node:
  37. +
  38. [source,yaml]
  39. --------------------------------------------------------------------------------
  40. node.attr.data: "warm"
  41. --------------------------------------------------------------------------------
  42. * A server with {filebeat} installed and configured to send logs to the `elasticsearch`
  43. output as described in the {filebeat-ref}/filebeat-installation-configuration.html[{filebeat} quick start].
  44. [discrete]
  45. [[example-using-index-lifecycle-policy-view-fb-ilm-policy]]
  46. ==== View the {filebeat} {ilm-init} policy
  47. {filebeat} includes a default {ilm-init} policy that enables rollover. {ilm-init}
  48. is enabled automatically if you’re using the default `filebeat.yml` and index template.
  49. To view the default policy in {kib}:
  50. . Go to Management and select *Index Lifecycle Policies*.
  51. . Search for _filebeat_
  52. . Select the _filebeat-version_ policy.
  53. This policy initiates the rollover action when the index size reaches 50GB or
  54. becomes 30 days old.
  55. [role="screenshot"]
  56. image::images/ilm/tutorial-ilm-hotphaserollover-default.png["Default policy"]
  57. [discrete]
  58. ==== Modify the policy
  59. The default policy is enough to prevent the creation of many tiny daily indices.
  60. You can modify the policy to meet more complex requirements.
  61. . Activate the warm phase.
  62. +
  63. --
  64. [role="screenshot"]
  65. image::images/ilm/tutorial-ilm-modify-default-warm-phase-rollover.png["Modify to add warm phase"]
  66. .. Set one of the following options to control when the index moves to the warm phase:
  67. *** Provide a value for *Timing for warm phase*. Setting this to *15* keeps the
  68. indices on hot nodes for a range of 15-45 days, depending on when the initial
  69. rollover occurred.
  70. *** Enable *Move to warm phase on rollover*. The index might move to the warm phase
  71. more quickly than intended if it reaches the *Maximum index size* before the
  72. the *Maximum age*.
  73. .. In the *Select a node attribute to control shard allocation* dropdown, select
  74. *data:warm(2)* to migrate shards to warm data nodes.
  75. .. Change *Number of replicas* to *1*.
  76. .. Enable *Force merge data* and set *Number of segments* to *1*.
  77. NOTE: When rollover is enabled in the hot phase, action timing in the other phases
  78. is based on the rollover date.
  79. --
  80. . Activate the delete phase and set *Timing for delete phase* to *90* days.
  81. +
  82. [role="screenshot"]
  83. image::images/ilm/tutorial-ilm-delete-rollover.png["Add a delete phase"]
  84. [discrete]
  85. ==== Create a custom policy
  86. If meeting a specific retention time period is most important, you can create a
  87. custom policy. For this option, you use {filebeat} daily indices without
  88. rollover.
  89. To create a custom policy:
  90. . Go to Management and select *Index Lifecycle Policies*.
  91. . Click *Create policy*.
  92. . Activate the warm phase and configure it as follows:
  93. +
  94. --
  95. **Timing for warm phase**: 30 days from index creation
  96. **Node attribute**: `data:warm`
  97. **Number of replicas**: 1
  98. **Force merge data**: enable
  99. **Number of segments**: 1
  100. [role="screenshot"]
  101. image::images/ilm/tutorial-ilm-custom-policy.png["Modify the custom policy to add a warm phase"]
  102. --
  103. . Activate the delete phase and set the timing to 90 days.
  104. +
  105. [role="screenshot"]
  106. image::images/ilm/tutorial-ilm-delete-phase-creation.png["Delete phase"]
  107. To configure the index to use the new policy:
  108. . Go to Management and select *Index Lifecycle Policies*.
  109. . Find your {ilm-init} policy and click its *Actions* link.
  110. . Choose *Add policy to index template*.
  111. . Select your {filebeat} index template name from the *Index template* list. For example, `filebeat-7.5.x`.
  112. . Click *Add Policy* to save the changes.
  113. +
  114. NOTE: If you initially used the default {filebeat} {ilm-init} policy, you will
  115. see a notice that the template already has a policy associated with it. Confirm
  116. that you want to overwrite that configuration.
  117. When you change the policy associated with the index template, the active
  118. index will continue to use the policy it was associated with at index creation
  119. unless you manually update it. The next new index will use the updated policy.
  120. For more reasons that your {ilm-init} policy changes might be delayed, see
  121. <<update-lifecycle-policy, Update Lifecycle Policy>>.