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