Skip to content

Monitoring & logging: Elasticsearch

Elasticsearch commands from the Monitoring & logging folder.

Index
6 items

Elasticsearch: Check cluster health

Safe

Status green / yellow / red, node count and unassigned shards.

curl -s "<es-url>/_cluster/health?pretty"
What each part does
  1. curl -sHTTP request, no progress bar
  2. <es-url>cluster address, e.g. http://localhost:9200 (add -u user:pass if secured)
  3. /_cluster/healthcluster status: green / yellow (replicas unassigned) / red (primaries missing), shard counts
  4. ?prettyindent the JSON

Also known as: cluster red · cluster yellow · _cluster/health

Elasticsearch: Explain unassigned shards

Safe

Why the first unassigned shard can't be allocated (disk watermark, node left…).

curl -s "<es-url>/_cluster/allocation/explain?pretty"
What each part does
  1. curl -sHTTP request, quiet
  2. /_cluster/allocation/explainexplains why the first unassigned shard can't be placed (disk, filters, node left...)
  3. ?prettyindent the JSON

Also known as: unassigned shards · cluster yellow · allocation explain

Elasticsearch: List indices by size

Safe

Biggest indices first, with doc count and health.

curl -s "<es-url>/_cat/indices?v&s=store.size:desc" | head -20
What each part does
  1. curl -sHTTP request, quiet
  2. /_cat/indicesone line per index: health, status, docs, size
  3. ?vadd a header row
  4. &s=store.size:descsort by size, biggest first
  5. | head -20keep the header + top 19

Also known as: _cat/indices · index size

Elasticsearch: Search recent error logs

Safe

Last 20 error-level documents. Change the field to match your log schema.

curl -s "<es-url>/<index-pattern>/_search?q=level:error&size=20&sort=@timestamp:desc&pretty"
What each part does
  1. curl -sHTTP request, quiet
  2. <index-pattern>/_searchsearch across matching indices, e.g. logs-*
  3. q=level:errorLucene query string: documents where level is error
  4. size=20return 20 hits
  5. sort=@timestamp:descnewest first
  6. prettyindent the JSON

Also known as: kibana search · elk logs

Elasticsearch: Clear read-only block after disk full

Caution

Re-enables writes once you've freed disk space below the flood-stage watermark.

curl -X PUT "<es-url>/_all/_settings" -H 'Content-Type: application/json' -d '{"index.blocks.read_only_allow_delete": null}'
What each part does
  1. curl -X PUTHTTP PUT: update settings
  2. "<es-url>/_all/_settings"the settings of every index
  3. -H 'Content-Type: application/json'tell ES the body is JSON
  4. -d '{"index.blocks.read_only_allow_delete": null}'body: reset the block ES set when disk hit the flood-stage watermark

My note Recent versions clear the block automatically once disk drops under the high watermark.

Also known as: FORBIDDEN/12/index read-only / allow delete (api) · flood stage disk watermark · read_only_allow_delete

Elasticsearch: Delete old indices

Destructive

Drop an index to free disk. Prefer ILM policies for routine retention.

curl -X DELETE "<es-url>/<index-name>"
What each part does
  1. curl -X DELETEHTTP DELETE
  2. "<es-url>/<index-name>"the index to delete for good; wildcards may be blocked by action.destructive_requires_name

My note Wildcard deletes are blocked by default (action.destructive_requires_name). Keep it that way.

Also known as: delete index · free disk elasticsearch

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…