Manage indexes with Curator

Updated at:

Curator is an index management tool provided by Elasticsearch. It allows you to delete, create, and close indexes, and to merge index segments. This topic describes how to use Curator, including how to install Curator, use the singleton command line interface, schedule tasks with cron, separate hot and cold data, and migrate indexes across nodes.

Install Curator

Prerequisites

  • An Alibaba Cloud Elasticsearch cluster is created.

    For more information, see Create an Alibaba Cloud Elasticsearch cluster.

  • An Alibaba Cloud Elastic Compute Service (ECS) instance is created and a Python environment is prepared.

    This topic uses an ECS instance that runs CentOS 7.3 64-bit as an example. The ECS instance must reside in the same region and zone as your Alibaba Cloud Elasticsearch cluster, and in the same virtual private cloud (VPC). For more information, see Custom Launch.

Procedure

  1. Connect to the ECS instance. For more information, see Connect to Linux.

    Note

    This topic uses a regular user account as an example.

  2. Run the following command to install Curator.

    sudo pip install elasticsearch-curator
    Note
    • We recommend that you install Curator 5.6.0, which supports Alibaba Cloud Elasticsearch 5.5.3 and 6.3.2. For more information about the compatibility between Curator versions and Elasticsearch versions, see Version Compatibility.

    • For more information about Curator, see Curator.

  3. After Curator is installed, run the following command to view the Curator version.

    sudo curator --version

    If the installation is successful, the following output is returned:

    curator, version 5.6.0

Use the singleton command line interface

You can run the curator_cli command to perform a single action. For more information about how to use the command, see Singleton Command Line Interface.

Note
  • The curator_cli command can perform only one action.

  • Not all actions can be performed by using the singleton command line interface. For example, the Alias and Restore actions are not supported.

Schedule tasks with cron

You can use cron and the curator command to perform a series of actions on a schedule.

The syntax of the curator command is as follows:

curator [OPTIONS] ACTION_FILE
Options:
  --config PATH  Path to configuration file. Default: ~/.curator/curator.yml
  --dry-run      Do not perform any changes.
  --version      Show the version and exit.
  --help         Show this message and exit.

When you run the curator command, you must specify the config.yml file and the action.yml file. For more information, see config.yml documentation and action.yml documentation.

Separate hot and cold data

For more information about the procedure, see "Hot-Warm" Architecture in Elasticsearch 5.x.

Migrate indexes from hot nodes to warm nodes

  1. In the /usr/curator/ directory, create a config.yml file. Use the following sample configuration:

    client:
      hosts:
        - http://es-cn-0pxxxxxxxxxxxx234.elasticsearch.aliyuncs.com
      port: 9200
      url_prefix:
      use_ssl: False
      certificate:
      client_cert:
      client_key:
      ssl_no_validate: False
      http_auth: user:password
      timeout: 30
      master_only: False
    logging:
      loglevel: INFO
      logfile:
      logformat: default
      blacklist: ['elasticsearch', 'urllib3']
    • hosts: Replace this value with the internal or public endpoint of your Alibaba Cloud Elasticsearch cluster. In this example, an internal endpoint is used.

    • http_auth: Replace this value with the username and password of your Alibaba Cloud Elasticsearch cluster.

  2. In the /usr/curator/ directory, create an action.yml file. Use the following sample configuration:

    actions:
      1:
        action: allocation
        description: "Apply shard allocation filtering rules to the specified indices"
        options:
          key: box_type
          value: warm
          allocation_type: require
          wait_for_completion: true
          timeout_override:
          continue_if_exception: false
          disable_action: false
        filters:
        - filtertype: pattern
          kind: prefix
          value: logstash-
        - filtertype: age
          source: creation_date
          direction: older
          timestring: '%Y-%m-%dT%H:%M:%S'
          unit: minutes
          unit_count: 30

    The preceding sample configuration migrates indexes that were created more than 30 minutes ago on hot nodes and whose names start with logstash- to warm nodes. You can also customize the action.yml file based on your business requirements.

  3. Run the following command to verify that the curator command can run properly:

    sudo curator --config /usr/curator/config.yml /usr/curator/action.yml

    If the command runs properly, output similar to the following is returned:

    2019-02-12 20:11:30,607 INFO      Preparing Action ID: 1, "allocation"
    2019-02-12 20:11:30,612 INFO      Trying Action ID: 1, "allocation": Apply shard allocation filtering rules to the specified indices
    2019-02-12 20:11:30,693 INFO      Updating index setting {'index.routing.allocation.require.box_type': 'warm'}
    2019-02-12 20:12:57,925 INFO      Health Check for all provided keys passed.
    2019-02-12 20:12:57,925 INFO      Action ID: 1, "allocation" completed.
    2019-02-12 20:12:57,925 INFO      Job completed.
  4. Run the following command to use cron to run the curator command every 15 minutes:

    crontab -e
    */15 * * * * curator --config /usr/curator/config.yml /usr/curator/action.yml