Operations 19 min read

Master Elasticsearch Cluster: Essential Commands for Health, Tasks, and Settings

This article explains how to manage Tencent Cloud Elasticsearch clusters by using key APIs to check health status, monitor pending tasks, retrieve metadata, view statistics, adjust shard allocation, modify cluster settings, and control tasks, providing practical command examples and detailed explanations for effective operations.

Efficient Ops
Efficient Ops
Efficient Ops
Master Elasticsearch Cluster: Essential Commands for Health, Tasks, and Settings

Tencent Cloud Elasticsearch Service offers a fully managed cloud solution that lets users create and manage clusters with a single click, simplifying deployment, scaling, and maintenance for log analysis, anomaly monitoring, website search, enterprise search, and BI analytics.

Cluster Related Commands

Before diving into common ES cluster commands, it is useful to review the basic distributed architecture: an ES cluster consists of multiple nodes, one of which is elected as the master node to manage and schedule the cluster. Each node stores a portion of index data, which is divided into shards, and each shard contains one or more segments that hold the actual documents.

When a client performs a write operation, the request first reaches a coordinating node, which determines the primary shard’s node and forwards the request. After the primary shard writes successfully, the request is replicated to the replica shard nodes, and finally the coordinating node returns a success response to the client.

Elasticsearch distributed architecture diagram
Elasticsearch distributed architecture diagram

1. View Cluster Health

GET _cluster/health

The response includes cluster name, health status (green, yellow, red), number of nodes, data nodes, active primary shards, active shards, relocating shards, initializing shards, unassigned shards, and the percentage of active shards. If the status is not green, the active_shards_percent_as_number field helps track recovery progress.

Additional parameters allow checking health at the indices or shards level:

GET /_cluster/health?level=indices</code><code>GET /_cluster/health?level=shards

Specific index health can be queried as well:

GET /_cluster/health/wr_index_1?level=indices</code><code>GET /_cluster/health/wr_index_1?level=shards
Cluster health example
Cluster health example

2. View Pending Tasks

GET /_cat/pending_tasks

This API lists pending tasks with fields such as insertOrder, timeInQueue, priority, and source. Task priorities (from highest to lowest) are IMMEDIATE > URGENT > HIGH > NORMAL > LOW > LANGUID. Understanding task priorities helps diagnose master node overload.

3. View Cluster Metadata

GET /_cluster/state/<metrics>/<target>

The API returns extensive metadata, including node names, IPs, ports, node attributes, index templates, shard routing, and snapshot information. To retrieve only metadata: GET /_cluster/state/metadata To view only routing tables: GET /_cluster/state/routing_table Routing information for a specific index can be obtained with:

GET /_cluster/state/routing_table/wr_index_1
Routing table metadata
Routing table metadata

4. View Cluster Statistics

GET /_cluster/stats

This API provides cluster‑level metrics such as the number of shards, storage size, memory and disk usage, node count, JVM version, and CPU usage.

Cluster stats
Cluster stats

5. Explain Unassigned Shards

GET _cluster/allocation/explain

This API explains why a shard is unassigned. For example, a replica added to a cluster may cause unassigned shards with the reason REPLICA_ADDED. The response details node decisions and decider explanations.

Unassigned shard explanation
Unassigned shard explanation

6. Change Shard Allocation

POST /_cluster/reroute

The reroute API allows manual shard movement. Supported commands include:

move : relocate a shard from one node to another.

cancel : cancel a relocation or recovery.

allocate_stale_primary : allocate a stale primary shard (requires accept_data_loss:true).

allocate_empty_primary : allocate an empty primary shard when data loss is acceptable.

{
  "commands": [
    { "move": { "index": "wr_index_1", "shard": 0, "from_node": "1626803143110145332", "to_node": "1626803143110145432" } }
  ]
}

7. View and Set Cluster Settings

GET /_cluster/settings

Shows current persistent and transient settings. Common modifications include adjusting shard recovery concurrency, disk watermarks, excluding nodes, setting minimum master nodes, making the cluster read‑only, toggling X‑Pack monitoring, and limiting total shards per node.

PUT /_cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.node_concurrent_recoveries": "8",
    "cluster.routing.allocation.cluster_concurrent_rebalance": "8",
    "indices.recovery.max_bytes_per_sec": "80mb"
  },
  "transient": {
    "cluster.routing.allocation.node_concurrent_recoveries": "8",
    "cluster.routing.allocation.cluster_concurrent_rebalance": "8",
    "indices.recovery.max_bytes_per_sec": "80mb"
  }
}

8. View Cluster Tasks

GET /_tasks

The tasks API lists currently running tasks on each node. Detailed information can be obtained by adding detailed=true. Tasks can be cancelled with POST _tasks/_cancel or via the _cat/tasks endpoint.

Tasks API output
Tasks API output

Cluster Operations Command Summary

The article summarizes the most frequently used cluster‑level commands for health checking, task monitoring, metadata inspection, statistics gathering, shard allocation explanation, manual rerouting, settings management, and task control.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

APIsettingsCluster Management
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.