Databases 15 min read

Master Elasticsearch with cURL: Monitor Cluster, CRUD, Bulk & MSearch Commands

After setting up an ES cluster, this guide shows how to use cURL to inspect node and master status, query cluster health, perform CRUD operations, manage indices, execute bulk actions, and run multi‑search queries, complete with example commands for both Kibana and Bash.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Elasticsearch with cURL: Monitor Cluster, CRUD, Bulk & MSearch Commands

After the Elasticsearch cluster is set up, you can use curl to query the cluster, check the master node, view health, and perform various CRUD operations.

CURL syntax

curl -X<VERB> '<PROTOCOL>://<HOST>:<PORT>/<PATH>?<QUERY_STRING>' -d '<BODY>'

VERB: GET, POST, PUT, DELETE etc.; PROTOCOL: usually http; HOST: IP or hostname; PORT: node port; PATH: e.g., _cat, _search, _cluster; QUERY_STRING: query parameters; -d: request body in JSON.

Basic Elasticsearch queries

# View supported _cat endpoints
curl -XGET -u elastic:26tBktGolYCyZD2pPISW 'http://192.168.31.215:9201/_cat'

# View master node
curl -XGET -u elastic:26tBktGolYCyZD2pPISW 'http://192.168.31.215:9201/_cat/master?v'

# View all nodes
curl -XGET -u elastic:26tBktGolYCyZD2pPISW 'http://192.168.31.215:9201/_cat/nodes?v'

# View all indices
curl -XGET -u elastic:26tBktGolYCyZD2pPISW 'http://192.168.31.215:9201/_cat/indices?v'

# View a single index
curl -XGET -u elastic:26tBktGolYCyZD2pPISW 'http://192.168.31.215:9201/_cat/indices/movies?v'

# View all shards
curl -XGET -u elastic:26tBktGolYCyZD2pPISW 'http://192.168.31.215:9201/_cat/shards?v'

# View shards of a single index
curl -XGET -u elastic:26tBktGolYCyZD2pPISW 'http://192.168.31.215:9201/_cat/shards/movies?v'

# Cluster health
curl -XGET -u elastic:26tBktGolYCyZD2pPISW 'http://192.168.31.215:9201/_cluster/health?pretty'

# List plugins
curl -XGET -u elastic:26tBktGolYCyZD2pPISW 'http://192.168.31.215:9201/_cat/plugins?v'

# Count all documents
curl -XGET -u elastic:26tBktGolYCyZD2pPISW 'http://192.168.31.215:9201/_all/_count?pretty'

# Count documents in a specific index
curl -XGET -u elastic:26tBktGolYCyZD2pPISW 'http://192.168.31.215:9201/movies/_count?pretty'

CRUD operations

Operation

Method

Endpoint

Description

Create (specified ID)

PUT

/index/_create/id

Fails if ID exists.

Create (auto ID)

POST

/index/_doc

Generates a new ID.

Index (upsert)

PUT/POST

/index/_doc/id

Creates or replaces document; version increments.

Read

GET

/index/_doc/id

Retrieves a document.

Update

POST

/index/_update/id

Partial update; document must exist.

Delete document

DELETE

/index/_doc/id

Removes a specific document.

Delete index

DELETE

/index

Removes the index and all its documents.

Create index and document examples

# Auto‑generated ID (Kibana)
POST /index/_doc
{
  "name": "WeiLiang Xu",
  "Blogs": "abcops.cn",
  "Is male": true,
  "age": 25
}

# Specified ID (Kibana)
POST /index/_create/1
{
  "name": "WeiLiang Xu",
  "Blogs": "abcops.cn",
  "Is male": true,
  "age": 25
}

Index (upsert) example

# Create or replace document with ID 6
POST /index/_doc/6
{
  "name": "WeiLiang Xu",
  "Blogs": "abcops.cn",
  "Is male": true,
  "age": 25
}

Read example

# Get document ID 1
GET /index/_doc/1

Update example

POST /weiliang/_update/1
{
  "doc": {
    "name": ["weiliang Xu", "xueiliang"],
    "JobS": "Linux DevOps",
    "Age": 25,
    "gender": "man"
  }
}

Delete examples

# Delete a document
DELETE /weiliang/_doc/1

# Delete an index
DELETE /weiliang

Bulk API

The bulk API allows multiple actions (index, create, update, delete) on one or many indices in a single request.

POST _bulk
{ "create": { "_index": "bulk_index", "_id": "1" } }
{ "Job": "Linux Ops" }
{ "delete": { "_index": "bulk_index", "_id": "2" } }
{ "update": { "_index": "bulk_index", "_id": "1" } }
{ "doc": { "name": "xuweiliang" } }
{ "index": { "_index": "bulk_index", "_id": "1" } }
{ "name": "xuweiliang" }
{ "create": { "_index": "bulk_index", "_id": "2" } }
{ "name": "xuweiliang", "Age": 25 }
{ "delete": { "_index": "bulk_index", "_id": "2" } }

Each line is processed independently; failures do not stop subsequent actions.

MGET – batch get

GET _mget
{
  "docs": [
    { "_index": "bulk_index", "_id": 1 },
    { "_index": "bulk_index", "_id": 2 },
    { "_index": "index", "_id": 1 }
  ]
}

MSEARCH – multi‑search

# requests file (NDJSON)
{ "index": "test" }
{ "query": { "match_all": {} }, "from": 0, "size": 10 }
{ "index": "test", "search_type": "dfs_query_then_fetch" }
{ "query": { "match_all": {} } }
{ }
{ "query": { "match_all": {} } }
{ "search_type": "dfs_query_then_fetch" }
{ "query": { "match_all": {} } }

Common error responses

Problem

Cause

Cannot connect

Network failure or cluster down

Connection cannot close

Network issue or node error

429

Cluster overloaded

4xx

Bad request format

500

Internal cluster error

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.

ElasticsearchCRUDcURLbulk APICluster MonitoringMSearch
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.