Elasticsearch Curator

9.0.0 · active · verified Thu Apr 16

Elasticsearch Curator is a tool designed to manage Elasticsearch indices and snapshots programmatically via YAML configuration files. It simplifies tasks like deleting old indices, optimizing shards, or closing/opening indices. Currently at version 9.0.0, it follows an active release cadence, with major releases aligning with Elasticsearch versions and frequent patch releases for bug fixes and minor features.

Common errors

Warnings

Install

Imports

Quickstart

The primary way to use Elasticsearch Curator is via its command-line interface with YAML configuration files for client settings and actions. This quickstart demonstrates how to check the installed version and simulate an action in dry-run mode using Python's `subprocess` module, which is common for interacting with CLI tools.

import subprocess
import os

# Most common usage is via CLI with configuration files.
# Example: Create a dummy action file and run curator in dry-run.

# Create a dummy action configuration file
action_config_content = """
actions:
  1:
    action: delete_indices
    description: "Delete indices older than 30 days matching 'logstash-'"
    options:
      ignore_empty_list: True
      timeout_override:
      continue_if_exception: False
      disable_action: False
      dry_run: True # Always set dry_run in example code for safety
    filters:
      - filtertype: pattern
        kind: prefix
        value: logstash-
      - filtertype: age
        source: name
        direction: older
        unit: days
        unit_count: 30
"""
action_file_path = "curator_action.yml"
with open(action_file_path, "w") as f:
    f.write(action_config_content)

try:
    # Get Curator version to check installation
    print("Checking Curator version:")
    version_result = subprocess.run(
        ["curator", "--version"], capture_output=True, text=True, check=True
    )
    print(version_result.stdout.strip())

    # Simulate running an action in dry-run mode
    print("\nSimulating an index deletion action (dry-run):")
    # Note: A client configuration is typically also needed in a separate file,
    # or specified via CLI arguments like --host, --port etc.
    # For simplicity, this example assumes default client config or
    # that ES is running on localhost:9200 and no auth is needed.
    # For a real run, create a 'curator.yml' client config file or pass
    # client options directly.
    dry_run_result = subprocess.run(
        ["curator", "--host", "localhost", "--port", "9200", action_file_path, "--dry-run"],
        capture_output=True,
        text=True,
        check=True
    )
    print(dry_run_result.stdout)
    if dry_run_result.stderr:
        print("STDERR:", dry_run_result.stderr)

except FileNotFoundError:
    print("Error: 'curator' command not found. Is elasticsearch-curator installed?")
except subprocess.CalledProcessError as e:
    print(f"Curator command failed with exit code {e.returncode}")
    print(f"STDOUT: {e.stdout}")
    print(f"STDERR: {e.stderr}")
finally:
    if os.path.exists(action_file_path):
        os.remove(action_file_path)

print("\nThis demonstrates how to run a Curator action in dry-run mode.")
print("For actual index management, remove '--dry-run' and ensure Elasticsearch is running.")
print("Refer to official documentation for full client and action configuration.")

view raw JSON →