Elasticsearch Examples: Viewing Cluster, Node and Index State

Elasticsearch Examples: Viewing Cluster, Node and Index State

Last updated:
Table of Contents

Tested on elasticsearch versions v2 through v7.12.1

List indexes in cluster

Seeing 3 indices: my-index-1, my-index-2 and my-index-3

$ curl --silent 'http://localhost:9200/_cat/indices'| sed 's/\s\s*/ /g' | sort
yellow open my-index-1 lYQOirBwSPurSAunxAU3mQ 1 1 0 0 208b 208b
yellow open my-index-2 -QyjBWHvTZe3iuq3ys7Q0A 1 1 0 0 208b 208b
yellow open my-index-3 N_lWgWIKTGGzC18KA8R6PA 1 1 0 0 208b 208b

Create new index

$ curl --silent -X PUT http://localhost:9200/my-new-index

Document count per index

using jq to query the json response

$ curl --silent localhost:9200/_stats/docs | jq ."indices"
{
  "my-index-1": {
    "uuid": "lYQOirBwSPurSAunxAU3mQ",
    "primaries": {
      "docs": {
        "count": 0,
        "deleted": 0
      }
    },
    "total": {
      "docs": {
        "count": 0,
        "deleted": 0
      }
    }
  }
}

Cluster health

$ curl --silent localhost:9200/_cluster/health?pretty=true
{
  "cluster_name": "elasticsearch",
  "status": "yellow",
  "timed_out": false,
  "number_of_nodes": 1,
  "number_of_data_nodes": 1,
  "active_primary_shards": 1,
  "active_shards": 1,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 1,
  "delayed_unassigned_shards": 0,
  "number_of_pending_tasks": 0,
  "number_of_in_flight_fetch": 0,
  "task_max_waiting_in_queue_millis": 0,
  "active_shards_percent_as_number": 50
}

Percentage of CPU being used in each node

using jq to query the json response

$ curl --silent localhost:9200/_nodes/stats/os | jq '.nodes[].os.cpu.percent'
8
10

Disk usage per node

using jq to query the json response

$ curl --silent localhost:9200/_nodes/stats/fs | jq '.nodes[].fs.total'
{
  "total_in_bytes": 983296925696,
  "free_in_bytes": 957225222144,
  "available_in_bytes": 907205001216
}