0
0
ElasticsearchDebug / FixBeginner · 3 min read

How to Fix Index Read Only Error in Elasticsearch Quickly

The Elasticsearch index read only error happens when the index is set to read_only_allow_delete due to disk watermark limits. To fix it, remove this block by running PUT /your_index/_settings { "index.blocks.read_only_allow_delete": false }. This unlocks the index for writes again.
🔍

Why This Happens

Elasticsearch sets an index to read-only mode automatically when the disk usage on the node reaches a high watermark. This is to protect the cluster from running out of disk space. The index gets a setting called index.blocks.read_only_allow_delete set to true, which blocks write operations but allows deletes.

This happens without manual intervention when disk space is low.

json
PUT /my_index/_doc/1
{
  "field": "value"
}
Output
{ "error": { "type": "cluster_block_exception", "reason": "index [my_index] blocked by: [FORBIDDEN/8/index read-only (api)];" }, "status": 403 }
🔧

The Fix

To fix the read only error, you need to remove the read-only block from the index settings. This allows Elasticsearch to accept write operations again.

Run this command replacing your_index with your actual index name:

json
PUT /your_index/_settings
{
  "index.blocks.read_only_allow_delete": false
}
Output
{ "acknowledged": true }
🛡️

Prevention

To avoid this error in the future, monitor your disk space regularly and keep it below the high watermark threshold (default 90%). You can also adjust the watermark settings if needed.

  • Set up alerts for disk usage.
  • Increase disk capacity or clean up old data.
  • Adjust Elasticsearch watermarks in elasticsearch.yml if your environment requires.
⚠️

Related Errors

Other similar errors include:

  • Cluster Block Exception: Happens when the cluster is in read-only mode due to other reasons like snapshot in progress.
  • Disk Full Errors: Write operations fail because the disk is completely full.

Quick fixes usually involve freeing disk space and removing blocks from affected indices.

Key Takeaways

Elasticsearch sets indices to read-only when disk usage is too high to protect data.
Remove the read-only block with PUT index settings to allow writes again.
Monitor disk space and keep it below the high watermark to prevent this error.
Adjust disk watermark settings if your environment requires different thresholds.
Free disk space promptly to avoid cluster-wide write blocks.