解决 Elasticsearch 报错 cluster_block_exception 只读阻塞
分析 Elasticsearch 索引被置为 read-only 报 cluster_block_exception 根因,详解只读锁解除命令与动态配置维护步骤。
问题现象
向 Elasticsearch 执行文档插入或更新时抛出异常:
{
"error": {
"root_cause": [
{
"type": "cluster_block_exception",
"reason": "blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"
}
],
"type": "cluster_block_exception",
"reason": "blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"
},
"status": 403
}
写入被完全阻断。
触发根因
- 之前触发了磁盘洪水水位线保护,只读锁未被显式清理:系统自动设置了
index.blocks.read_only_allow_delete: true。 - 管理员执行过手动只读锁定未还原。
诊断排查步骤
- 查询索引设置确认只读锁状态:
curl -s http://elasticsearch:9200/my-index/_settings?pretty
查看 blocks.read_only 或 blocks.read_only_allow_delete 是否为 true。
解决步骤与操作命令
步骤一:确保磁盘使用率低于 85%
curl -s http://elasticsearch:9200/_cat/allocation?v
步骤二:调用 API 手动解除索引只读块锁
curl -X PUT "http://elasticsearch:9200/my-index/_settings" -H "Content-Type: application/json" -d '{
"index.blocks.read_only_allow_delete": null,
"index.blocks.read_only": null
}'
若涉及所有索引:
curl -X PUT "http://elasticsearch:9200/_all/_settings" -H "Content-Type: application/json" -d '{
"index.blocks.read_only_allow_delete": null,
"index.blocks.read_only": null
}'
验证方法
再次写入单条测试文档:
curl -X POST "http://elasticsearch:9200/my-index/_doc" -H "Content-Type: application/json" -d '{"test": "ok"}'
返回 result: created,HTTP 状态码恢复为 201 Created。


