Adding index lifecycle policy – How to solve this Elasticsearch error

Opster Team

Aug-23, Version: 7-8.9

Briefly, this error occurs when there’s an issue adding an index lifecycle management (ILM) policy to an Elasticsearch index. This could be due to a non-existent policy, incorrect policy name, or insufficient permissions. To resolve this, ensure the ILM policy exists and is correctly named. Also, check the user has the necessary permissions to add a policy. If the issue persists, consider reconfiguring the ILM policy or creating a new one.

Before you begin reading about how to address this log, we recommend you run the Elasticsearch Error Check-Up to resolve this issue and prevent others.

This guide will help you check for common problems that cause the log “adding index lifecycle policy” to appear. It’s important to understand the issues related to it, so to get started, read the general overview on common issues and tips related to the Elasticsearch concepts: index and plugin.

What the index lifecycle policy is

The index lifecycle management (commonly known as ILM) enables you to automate how you want to manage your indices over time. This will take care of automatically managing indices according to various requirements like performance, resilience, deleting old indices and retention requirements.

Refer to this documentation on ILM to learn more about this policy.

How to reproduce this log

To set up index lifecycle policy, you need to define the policy as shown below (change the policy according to your use case).

Create index lifecycle policy:

PUT /_ilm/policy/my_policy
{
 "policy": {
   "phases": {
     "warm": {
       "min_age": "10d",
       "actions": {
         "forcemerge": {
           "max_num_segments": 1
         }
       }
     },
     "delete": {
       "min_age": "20d",
       "actions": {
         "delete": {}
       }
     }
   }
 }
}

The log generated will be:

[INFO ][o.e.x.i.a.TransportPutLifecycleAction] adding index lifecycle policy [my_policy]

What this message means

It’s an INFO message letting you know that an index lifecycle management policy is set up. The first step is to define a lifecycle policy so that the index can use this ILM policy to manage its lifecycle. The above request creates a policy called my_policy in Elasticsearch which can be later used to manage the indices. When the policy is created, Elasticsearch will log it as shown above.

Log Context

Log “adding index lifecycle policy [{}]” classname is TransportPutLifecycleAction.java.
We extracted the following from Elasticsearch source code for those seeking an in-depth context :

                Instant.now().toEpochMilli()
            );
            LifecyclePolicyMetadata oldPolicy = newPolicies.put(lifecyclePolicyMetadata.getName(); lifecyclePolicyMetadata);
            if (verboseLogging) {
                if (oldPolicy == null) {
                    logger.info("adding index lifecycle policy [{}]"; request.getPolicy().getName());
                } else {
                    logger.info("updating index lifecycle policy [{}]"; request.getPolicy().getName());
                }
            }
            IndexLifecycleMetadata newMetadata = new IndexLifecycleMetadata(newPolicies; currentILMMode(currentState));

 

 [ratemypost]