Elasticsearch Agent Skill for intelligent cluster O&M

Updated at:

After installing the Skill, your AI agent can use natural language commands to call Alibaba Cloud Elasticsearch OpenAPI operations, performing O&M tasks like creating clusters, troubleshooting, and configuring security settings. Supported AI agent products include Claude Code, DataAgent, Cursor, and Qoder. The AI search agent Agentic Search will also be supported soon.

Skill overview

Skill name

Function

Capabilities

elasticsearch-instance-manage

Instance lifecycle management

Create (single- or multi-availability zone), query, list, restart, scale, and retrieve node information

elasticsearch-instance-diagnose

Intelligent fault diagnosis

Four-step diagnosis method, 49 diagnostic rules, 7 SOPs, and data collection from the control plane, monitoring system, and engine

elasticsearch-network-manage

Network security configuration

Public/private network switch, whitelist management, HTTPS, and Kibana PrivateLink

Install the skill

Install Aliyun CLI

The skill requires Aliyun CLI 3.3.3 or later to execute OpenAPI calls.

# Install or update Aliyun CLI
curl -fsSL https://aliyuncli.alicdn.com/setup.sh | bash

# Verify the version
aliyun version

# Enable automatic plugin installation
aliyun configure set --auto-plugin-install true
aliyun plugin update

If you have not configured your credentials, run aliyun configure to set them up.

Download and install the skill

  1. Go to the Alibaba Cloud Agent Skills Portal, navigate to the following skill detail pages, and download the installation packages:

  2. Unzip the downloaded packages into the skills directory of your project. The following example uses Claude Code:

    unzip alibabacloud-elasticsearch-instance-manage.zip -d your-project/.claude/skills/
    unzip alibabacloud-elasticsearch-instance-diagnose.zip -d your-project/.claude/skills/
    unzip alibabacloud-elasticsearch-network-manage.zip -d your-project/.claude/skills/
  3. Verify the directory structure:

    ls your-project/.claude/skills/
    # The output should show three skill directories, each containing SKILL.md and a references/ directory.

For other AI coding tools, unzip the packages to their corresponding skills directory. For example, for Cursor, use .cursor/rules/, and for Qoder, use its designated skills directory.

Scenario 1: Create an Elasticsearch instance

The instance management skill lets you describe creation requirements in natural language. The AI assistant then automatically validates parameters and makes the API calls.

Prompt for the AI assistant:

In the China (Hangzhou) region, create a dual-availability zone Elasticsearch instance. Use version 8.17_with_X-Pack, 4 data nodes, each with a 20 GB ESSD, and the elasticsearch.sn2ne.large.new specification. Use VPC vpc-bp1***************, vSwitch vsw-bp1***************, and availability zone cn-hangzhou-i. Set the billing method to pay-as-you-go and name the instance log-es-cluster.

The AI assistant automatically performs the following actions:

  1. Validates all required parameters, such as region, VPC, vSwitch, availability zone, password, and specification, prompting for any missing information.

  2. Recognizes the dual-availability zone requirement and automatically configures zoneCount=2 and three dedicated master nodes.

  3. Generates a clientToken (UUID) to ensure idempotence.

  4. Calls the createInstance API to create the instance.

  5. Queries the instance status to confirm successful creation.

Example command generated and executed by the AI assistant:

CLIENT_TOKEN=$(uuidgen)

aliyun elasticsearch create-instance \
  --region cn-hangzhou \
  --client-token $CLIENT_TOKEN \
  --es-admin-password "YourPassword@2024" \
  --es-version "8.17_with_X-Pack" \
  --node-amount 4 \
  --node-spec '{"disk":20,"diskType":"cloud_essd","spec":"elasticsearch.sn2ne.large.new"}' \
  --network-config '{"vpcId":"vpc-bp1***************","vswitchId":"vsw-bp1***************","vsArea":"cn-hangzhou-i","type":"vpc"}' \
  --payment-type postpaid \
  --description "log-es-cluster" \
  --zone-count 2 \
  --master-configuration '{"amount":3,"disk":20,"diskType":"cloud_essd","spec":"elasticsearch.sn2ne.xlarge"}' \
  --kibana-configuration '{"amount":1,"spec":"elasticsearch.n4.small"}' \
  --user-agent AlibabaCloud-Agent-Skills/alibabacloud-elasticsearch-instance-manage

Note the following constraints when you create an instance:

  • Multi-availability zone deployment: When you set zoneCount to 2 or 3, you must configure three dedicated master nodes. For network configuration, you only need to provide the vswitchId for the primary availability zone. Nodes are automatically distributed across different availability zones.

  • Idempotence protection: All write operations use a clientToken (in UUID format) to allow for safe retries after a request times out.

  • Single-change principle: When scaling an instance, you cannot modify data nodes, master nodes, Kibana nodes, cold nodes, and coordinating nodes in the same API call.

  • Specification differences: The supported node specifications vary by region. The skill includes a built-in specification map for automatic validation. In the China (Beijing), China (Shanghai), China (Hangzhou), and China (Shenzhen) regions, the specifications for new-generation cloud disk nodes require a .new suffix, for example, elasticsearch.sn2ne.large.new.

Scenario 2: Diagnose a cluster fault

The diagnosis skill uses a systematic four-step diagnostic workflow to address 8 major fault categories and incorporates 7 specialized Standard Operating Procedures (SOPs).

Prompt for the AI assistant:

My Elasticsearch cluster es-cn-xxx in the China (Hangzhou) region now has a Red health status. All production writes are failing. Urgently diagnose the cause and provide a solution.

The AI assistant automatically performs a four-step diagnosis:

Step

Actions

Data source

Quick scan

Calls DescribeInstance to confirm the cluster status

Alibaba Cloud OpenAPI

Concurrent collection

Collects metrics such as CPU, memory, and disk usage; queries system events; and gets the shard allocation status

Cloud Monitor + ES REST API

Rule matching

Matches collected signals against 49 reason codes and corresponding SOPs

Built-in diagnostic knowledge base

Diagnosis output

Provides a root cause analysis and recommended actions, prioritized by severity (P0, P1, and P2).

Comprehensive inference

Example diagnostic output:

P0 Critical Issue: Cluster health is Red
├─ Root Cause: Disk usage on node es-node-03 is at 96%, triggering the flood_stage read-only protection.
├─ Impact: Primary shards are unavailable, causing all write operations to fail.
├─ Recommended Actions:
│  1. Immediately delete expired indices to free up disk space.
│  2. After disk usage drops below 85%, run the following command:
│     PUT _all/_settings {"index.blocks.read_only_allow_delete": null}
│  3. Evaluate whether to scale up disk capacity.
└─ Reference SOPs: sop-disk-storage.md / sop-cluster-health.md

Common faults

Disk watermark tiered response: Elasticsearch has a three-tiered automatic protection mechanism.

Level

Trigger condition

Action

Low watermark

Disk usage > 85%

Stops allocating new shards to the node

High watermark

Disk usage > 90%

Attempts to relocate shards away from the node

Flood stage

Disk usage > 95%

Sets all indices on the node to read-only

After disk usage drops to a safe level, you must manually remove the read-only protection by running the following command:

PUT _all/_settings
{
  "index.blocks.read_only_allow_delete": null
}

Criteria for identifying JVM memory pressure:

Metric

Warning (P1)

Critical (P0)

Heap memory usage

avg > 75%

avg > 85%

Old GC frequency

> 1 per minute

—

GC time percentage

—

> 10%

Write optimization baselines (for HTTP 429 write rejections):

  • Bulk request size: 10 MB to 30 MB

  • Documents per bulk request: 500 to 2,000

  • Concurrent bulk requests: No more than twice the number of nodes

Scenario 3: Configure network security

The network management skill automatically identifies the instance's architecture type (cloud-native or basic-managed) and selects the appropriate API for network configuration.

Prompt for the AI assistant:

Enable HTTPS for the Elasticsearch instance es-cn-xxx. Also, append the IP ranges 203.0.113.0/24 and 198.51.100.0/24 to the public whitelist without overwriting the existing entries.

The AI assistant automatically performs the following actions:

  1. Calls DescribeInstance to check the instance status and current HTTPS state.

  2. If HTTPS is not enabled, it calls OpenHttps to enable it.

  3. Calls ModifyWhiteIps using the Append mode to add the IP addresses to the whitelist.

# Check the current HTTPS status
aliyun elasticsearch describe-instance \
  --instance-id es-cn-xxx \
  --user-agent AlibabaCloud-Agent-Skills/alibabacloud-elasticsearch-network-manage

# Enable HTTPS
aliyun elasticsearch open-https \
  --instance-id es-cn-xxx \
  --user-agent AlibabaCloud-Agent-Skills/alibabacloud-elasticsearch-network-manage

# Append to the whitelist (Append mode)
aliyun elasticsearch modify-white-ips \
  --instance-id es-cn-xxx \
  --modify-mode Append \
  --white-ip-group '{"groupName":"default","ips":["203.0.113.0/24","198.51.100.0/24"],"whiteIpType":"PUBLIC_ES"}' \
  --user-agent AlibabaCloud-Agent-Skills/alibabacloud-elasticsearch-network-manage

Key constraints for network configuration:

Operation

Description

Architecture awareness

The skill automatically queries the instance's archType. Different APIs are used for cloud-native (public) and basic-managed (exclusive) instances.

Kibana private network

For cloud-native instances, Kibana private network access must be configured using EnableKibanaPvlNetwork, not TriggerNetwork.

Whitelist mode

Three modes are available: Cover, Append, and Delete. Use Append when adding new IP addresses to avoid overwriting existing configurations.

Idempotence check

The skill automatically checks the current state before an operation. If the desired state is already met, the operation is skipped.

Security constraints

Avoid setting the whitelist to 0.0.0.0/0. Public whitelists do not support private IP addresses, and private whitelists do not support public IP addresses.

Timing of changes

The TriggerNetwork operation may cause a brief service interruption. We recommend performing this operation during off-peak hours.