# Index Lifecycle Management (ILM)

class elasticsearch.client.IlmClient

  To use this client, access `client.ilm` from an `Elasticsearch` client. For example:

      from elasticsearch import Elasticsearch

      # Create the client instance
      client = Elasticsearch(...)
      # Use the ilm client
      client.ilm.<method>(...)

  delete_lifecycle(*, name, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)

    Delete a lifecycle policy.

    You cannot delete policies that are currently in use. If the policy is being used to manage any indices, the request fails and returns an error.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-ilm-delete-lifecycle

    Parameters:

      - name (str) – Identifier for the policy.

      - master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 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.

      - timeout (str | Literal[-1] | ~typing.Literal[0] | None) – Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  explain_lifecycle(*, index, error_trace=None, filter_path=None, human=None, master_timeout=None, only_errors=None, only_managed=None, pretty=None)

    Explain the lifecycle state.

    Get the current lifecycle status for one or more indices. For data streams, the API retrieves the current lifecycle status for the stream's backing indices.

    The response indicates when the index entered each lifecycle state, provides the definition of the running phase, and information about any failures.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-ilm-explain-lifecycle

    Parameters:

      - index (str) – Comma-separated list of data streams, indices, and aliases to target. Supports wildcards (*). To target all data streams and indices, use * or _all.

      - master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 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.

      - only_errors (bool | None) – Filters the returned indices to only indices that are managed by ILM and are in an error state, either due to an encountering an error while executing the policy, or attempting to use a policy that does not exist.

      - only_managed (bool | None) – Filters the returned indices to only indices that are managed by ILM.

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  get_lifecycle(*, name=None, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)

    Get lifecycle policies.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-ilm-get-lifecycle

    Parameters:

      - name (str | None) – Identifier for the policy.

      - master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 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.

      - timeout (str | Literal[-1] | ~typing.Literal[0] | None) – Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  get_status(*, error_trace=None, filter_path=None, human=None, pretty=None)

    Get the ILM status.

    Get the current index lifecycle management status.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-ilm-get-status

    Parameters:

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  migrate_to_data_tiers(*, dry_run=None, error_trace=None, filter_path=None, human=None, legacy_template_to_delete=None, master_timeout=None, node_attribute=None, pretty=None, body=None)

    Migrate to data tiers routing.

    Switch the indices, ILM policies, and legacy, composable, and component templates from using custom node attributes and attribute-based allocation filters to using data tiers. Optionally, delete one legacy index template. Using node roles enables ILM to automatically move the indices between data tiers.

    Migrating away from custom node attributes routing can be manually performed. This API provides an automated way of performing three out of the four manual steps listed in the migration guide:

    1. Stop setting the custom hot attribute on new indices.
    2. Remove custom allocation settings from existing ILM policies.
    3. Replace custom allocation settings from existing indices with the corresponding tier preference.

    ILM must be stopped before performing the migration. Use the stop ILM and get ILM status APIs to wait until the reported operation mode is `STOPPED`.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-ilm-migrate-to-data-tiers

    Parameters:

      - dry_run (bool | None) – If true, simulates the migration from node attributes based allocation filters to data tiers, but does not perform the migration. This provides a way to retrieve the indices and ILM policies that need to be migrated.

      - legacy_template_to_delete (str | None)

      - master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – The 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. It can also be set to -1 to indicate that the request should never timeout.

      - node_attribute (str | None)

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

      - body (Dict[str, Any] | None)

    Return type:

      ObjectApiResponse[Any]

  move_to_step(*, index, current_step=None, next_step=None, error_trace=None, filter_path=None, human=None, pretty=None, body=None)

    Move to a lifecycle step.

    Manually move an index into a specific step in the lifecycle policy and run that step.

    WARNING: This operation can result in the loss of data. Manually moving an index into a specific step runs that step even if it has already been performed. This is a potentially destructive action and this should be considered an expert level API.

    You must specify both the current step and the step to be executed in the body of the request. The request will fail if the current step does not match the step currently running for the index This is to prevent the index from being moved from an unexpected step into the next step.

    When specifying the target (`next_step`) to which the index will be moved, either the name or both the action and name fields are optional. If only the phase is specified, the index will move to the first step of the first action in the target phase. If the phase and action are specified, the index will move to the first step of the specified action in the specified phase. Only actions specified in the ILM policy are considered valid. An index cannot move to a step that is not part of its policy.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-ilm-move-to-step

    Parameters:

      - index (str) – The name of the index whose lifecycle step is to change

      - current_step (Mapping[str, Any] | None) – The step that the index is expected to be in.

      - next_step (Mapping[str, Any] | None) – The step that you want to run.

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

      - body (Dict[str, Any] | None)

    Return type:

      ObjectApiResponse[Any]

  put_lifecycle(*, name, error_trace=None, filter_path=None, human=None, master_timeout=None, policy=None, pretty=None, timeout=None, body=None)

    Create or update a lifecycle policy.

    If the specified policy exists, it is replaced and the policy version is incremented.

    NOTE: Only the latest version of the policy is stored, you cannot revert to previous versions.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-ilm-put-lifecycle

    Parameters:

      - name (str) – Identifier for the policy.

      - master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 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.

      - policy (Mapping[str, Any] | None)

      - timeout (str | Literal[-1] | ~typing.Literal[0] | None) – Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

      - body (Dict[str, Any] | None)

    Return type:

      ObjectApiResponse[Any]

  remove_policy(*, index, error_trace=None, filter_path=None, human=None, pretty=None)

    Remove policies from an index.

    Remove the assigned lifecycle policies from an index or a data stream's backing indices. It also stops managing the indices.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-ilm-remove-policy

    Parameters:

      - index (str) – The name of the index to remove policy on

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  retry(*, index, error_trace=None, filter_path=None, human=None, pretty=None)

    Retry a policy.

    Retry running the lifecycle policy for an index that is in the ERROR step. The API sets the policy back to the step where the error occurred and runs the step. Use the explain lifecycle state API to determine whether an index is in the ERROR step.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-ilm-retry

    Parameters:

      - index (str) – The name of the indices (comma-separated) whose failed lifecycle step is to be retry

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  start(*, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)

    Start the ILM plugin.

    Start the index lifecycle management plugin if it is currently stopped. ILM is started automatically when the cluster is formed. Restarting ILM is necessary only when it has been stopped using the stop ILM API.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-ilm-start

    Parameters:

      - master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 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.

      - timeout (str | Literal[-1] | ~typing.Literal[0] | None) – Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  stop(*, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)

    Stop the ILM plugin.

    Halt all lifecycle management operations and stop the index lifecycle management plugin. This is useful when you are performing maintenance on the cluster and need to prevent ILM from performing any actions on your indices.

    The API returns as soon as the stop request has been acknowledged, but the plugin might continue to run until in-progress operations complete and the plugin can be safely stopped. Use the get ILM status API to check whether ILM is running.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-ilm-stop

    Parameters:

      - master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 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.

      - timeout (str | Literal[-1] | ~typing.Literal[0] | None) – Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]