IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Create or update lifecycle policy API
editCreate or update lifecycle policy API
editCreates or updates lifecycle policy. See Index lifecycle for definitions of policy components.
Request
editPUT _ilm/policy/<policy_id>
Prerequisites
edit-
If the Elasticsearch security features are enabled, you must have the
manage_ilm
cluster privilege to use this API. You must also have themanage
index privilege on all indices being managed bypolicy
. ILM performs operations as the user who last updated the policy. ILM only has the roles assigned to the user at the time of the last policy update.
Description
editCreates a lifecycle policy. If the specified policy exists, the policy is replaced and the policy version is incremented.
Only the latest version of the policy is stored, you cannot revert to previous versions.
Path parameters
edit-
<policy_id>
- (Required, string) Identifier for the policy.
Query parameters
edit-
master_timeout
-
(Optional, time units)
Period to wait for a connection to the master node. If no response is received
before the timeout expires, the request fails and returns an error. Defaults to
30s
. -
timeout
-
(Optional, time units)
Period to wait for a response. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to
30s
.
Examples
editThe following example creates a new policy named my_policy
. In addition, you can use the
_meta
parameter to add arbitrary metadata to the policy, the _meta
parameter is optional
and not automatically generated or used by Elasticsearch. To unset _meta
, replace the policy
without specifying one. To check the _meta
, you can use the Get lifecycle policy API.
response = client.ilm.put_lifecycle( policy: 'my_policy', body: { policy: { _meta: { description: 'used for nginx log', project: { name: 'myProject', department: 'myDepartment' } }, phases: { warm: { min_age: '10d', actions: { forcemerge: { max_num_segments: 1 } } }, delete: { min_age: '30d', actions: { delete: {} } } } } } ) puts response
PUT _ilm/policy/my_policy { "policy": { "_meta": { "description": "used for nginx log", "project": { "name": "myProject", "department": "myDepartment" } }, "phases": { "warm": { "min_age": "10d", "actions": { "forcemerge": { "max_num_segments": 1 } } }, "delete": { "min_age": "30d", "actions": { "delete": {} } } } } }
If the request succeeds, you receive the following result:
{ "acknowledged": true }