2018-10-26 15:19:52 -04:00
|
|
|
[role="xpack"]
|
|
|
|
[testenv="basic"]
|
2018-08-13 16:15:15 -04:00
|
|
|
[[set-up-lifecycle-policy]]
|
2020-04-28 19:38:01 -04:00
|
|
|
== Configure lifecycle policy [[ilm-policy-definition]]
|
2018-08-13 16:15:15 -04:00
|
|
|
|
2020-04-28 19:38:01 -04:00
|
|
|
For {ilm-init} to manage an index, a valid policy
|
|
|
|
must be specified in the `index.lifecycle.name` index setting.
|
|
|
|
|
|
|
|
To configure a lifecycle policy for rolling indices,
|
|
|
|
you create the policy and add it to the index template.
|
|
|
|
|
|
|
|
To use a policy to manage an index that doesn't roll over,
|
|
|
|
you can specify the policy directly when you create it.
|
|
|
|
|
|
|
|
[discrete]
|
|
|
|
[[ilm-create-policy]]
|
|
|
|
=== Create lifecycle policy
|
|
|
|
|
|
|
|
You use the <<ilm-put-lifecycle,create policy API>> to define a new lifecycle policy.
|
|
|
|
For example, the following request creates `my_policy`, a
|
|
|
|
policy that defines a hot and and delete phase.
|
|
|
|
When the index reaches 25GB, it rolls over directly to the delete phase.
|
|
|
|
The index is deleted 30 days after rollover.
|
2018-08-28 10:47:01 -04:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2018-08-28 10:47:01 -04:00
|
|
|
------------------------
|
2018-10-30 19:19:05 -04:00
|
|
|
PUT _ilm/policy/my_policy
|
2018-08-28 10:47:01 -04:00
|
|
|
{
|
|
|
|
"policy": {
|
|
|
|
"phases": {
|
|
|
|
"hot": {
|
|
|
|
"actions": {
|
|
|
|
"rollover": {
|
|
|
|
"max_size": "25GB" <1>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"delete": {
|
2018-10-30 15:54:02 -04:00
|
|
|
"min_age": "30d",
|
2018-08-28 10:47:01 -04:00
|
|
|
"actions": {
|
|
|
|
"delete": {} <2>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-16 13:49:55 -05:00
|
|
|
------------------------
|
2019-09-09 13:38:14 -04:00
|
|
|
|
2020-04-28 19:38:01 -04:00
|
|
|
<1> Roll over the index when it reaches 25GB in size
|
|
|
|
<2> Delete the index 30 days after rollover
|
2018-08-28 10:47:01 -04:00
|
|
|
|
2020-04-28 19:38:01 -04:00
|
|
|
NOTE: {ilm-init} policies are stored in the global cluster state and can be included in snapshots by
|
|
|
|
setting `include_global_state` to `true` when you <<snapshots-take-snapshot, take the snapshot>>.
|
|
|
|
Restoring {ilm-init} policies from a snapshot is all-or-nothing.
|
|
|
|
The entire global state, including all policies, is overwritten when you restore the snapshot.
|
2018-12-13 15:44:34 -05:00
|
|
|
|
2020-04-28 19:38:01 -04:00
|
|
|
[discrete]
|
|
|
|
[[apply-policy-template]]
|
|
|
|
=== Apply lifecycle policy with an index template
|
2018-08-28 10:47:01 -04:00
|
|
|
|
2020-04-28 19:38:01 -04:00
|
|
|
To use a policy that triggers the rollover action,
|
|
|
|
you need to configure the policy in the index template used to create each new index.
|
|
|
|
|
|
|
|
In addition to specifying the name of the policy in the `index.lifecycle.name` setting,
|
|
|
|
you specify a `index.lifecycle.rollover_alias` for referencing
|
|
|
|
the indices managed by this policy.
|
2018-08-28 10:47:01 -04:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2018-08-28 10:47:01 -04:00
|
|
|
-----------------------
|
|
|
|
PUT _template/my_template
|
|
|
|
{
|
|
|
|
"index_patterns": ["test-*"], <1>
|
|
|
|
"settings": {
|
|
|
|
"number_of_shards": 1,
|
|
|
|
"number_of_replicas": 1,
|
|
|
|
"index.lifecycle.name": "my_policy", <2>
|
2020-04-28 19:38:01 -04:00
|
|
|
"index.lifecycle.rollover_alias": "test-alias" <3>
|
2018-08-28 10:47:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
-----------------------
|
2019-09-09 13:38:14 -04:00
|
|
|
|
2020-04-28 19:38:01 -04:00
|
|
|
<1> Use this template for all new indices whose names begin with `test-`
|
|
|
|
<2> Apply `my_policy` to new indices created with this template
|
|
|
|
<3> Define an index alias for referencing indices managed by `my_policy`
|
2018-08-28 10:47:01 -04:00
|
|
|
|
2020-01-28 09:36:29 -05:00
|
|
|
//////////////////////////
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
|
|
|
DELETE /_template/my_template
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
|
2020-04-28 19:38:01 -04:00
|
|
|
[discrete]
|
|
|
|
[[create-initial-index]]
|
|
|
|
==== Create an initial managed index
|
|
|
|
|
|
|
|
You need to manually create the first index managed by a policy that uses the rollover action
|
|
|
|
and designate it as the write index.
|
|
|
|
The name of the index must match the pattern defined in the index template and end with a number.
|
|
|
|
This number is incremented to generate the name of indices created by the rollover action.
|
|
|
|
|
|
|
|
For example, the following request creates the `test-00001` index.
|
|
|
|
Because it matches the index pattern specified in `my_template`,
|
|
|
|
{es} automatically applies the settings from that template.
|
2018-08-28 10:47:01 -04:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2018-08-28 10:47:01 -04:00
|
|
|
-----------------------
|
2019-01-18 03:34:11 -05:00
|
|
|
PUT test-000001
|
2018-08-28 10:47:01 -04:00
|
|
|
{
|
|
|
|
"aliases": {
|
|
|
|
"test-alias":{
|
|
|
|
"is_write_index": true <1>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-----------------------
|
2019-09-09 13:38:14 -04:00
|
|
|
|
2018-08-28 10:47:01 -04:00
|
|
|
<1> Set this initial index to be the write index for this alias.
|
|
|
|
|
2020-04-28 19:38:01 -04:00
|
|
|
Now you can start indexing data to the rollover alias specified in the lifecycle policy.
|
|
|
|
With the sample `my_policy` policy, the rollover action is triggered once the initial
|
|
|
|
index exceeds 25GB.
|
|
|
|
{ilm-init} then creates a new index that becomes the write index for the `test-alias`.
|
2018-08-28 10:47:01 -04:00
|
|
|
|
2020-04-28 19:38:01 -04:00
|
|
|
[discrete]
|
|
|
|
[[apply-policy-manually]]
|
|
|
|
=== Apply lifecycle policy manually
|
2018-08-28 10:47:01 -04:00
|
|
|
|
2020-04-28 19:38:01 -04:00
|
|
|
When you create an index directly, you can apply a lifecycle policy
|
|
|
|
by specifying the `index.lifecycle.name` setting.
|
|
|
|
This causes {ilm-init} to immediately start managing the index.
|
2018-08-28 10:47:01 -04:00
|
|
|
|
2019-09-09 13:38:14 -04:00
|
|
|
[source,console]
|
2018-08-28 10:47:01 -04:00
|
|
|
-----------------------
|
2019-01-18 03:34:11 -05:00
|
|
|
PUT test-index
|
2018-08-28 10:47:01 -04:00
|
|
|
{
|
|
|
|
"settings": {
|
|
|
|
"number_of_shards": 1,
|
|
|
|
"number_of_replicas": 1,
|
|
|
|
"index.lifecycle.name": "my_policy"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-----------------------
|
2019-09-09 13:38:14 -04:00
|
|
|
|
2020-04-28 19:38:01 -04:00
|
|
|
IMPORTANT: Do not manually apply a policy that uses the rollover action.
|
|
|
|
Policies that use rollover must be applied by the <<apply-policy-template, index template>>.
|
|
|
|
Otherwise, the policy is not carried forward when the rollover action creates a new index.
|