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

<code>GET _cluster/health</code>

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:

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

Specific index health can be queried as well:

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

2. View Pending Tasks

<code>GET /_cat/pending_tasks</code>

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

<code>GET /_cluster/state/&lt;metrics&gt;/&lt;target&gt;</code>

The API returns extensive metadata, including node names, IPs, ports, node attributes, index templates, shard routing, and snapshot information. To retrieve only metadata:

<code>GET /_cluster/state/metadata</code>

To view only routing tables:

<code>GET /_cluster/state/routing_table</code>

Routing information for a specific index can be obtained with:

<code>GET /_cluster/state/routing_table/wr_index_1</code>
Routing table metadata
Routing table metadata

4. View Cluster Statistics

<code>GET /_cluster/stats</code>

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

<code>GET _cluster/allocation/explain</code>

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

<code>POST /_cluster/reroute</code>

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.

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

7. View and Set Cluster Settings

<code>GET /_cluster/settings</code>

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.

<code>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"
  }
}</code>

8. View Cluster Tasks

<code>GET /_tasks</code>

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.

operationsElasticsearchAPIsettingsCluster 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

login 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.