Elasticsearch index.blocks.read_only Setting

The index.blocks.read_only setting in Elasticsearch is used to make an index read-only. When set to true, it prevents any write operations on the index while still allowing read operations.

  • Default Value: false
  • Possible Values: true or false
  • Recommendations: Use this setting when you want to protect an index from accidental writes or modifications, or when you need to perform maintenance tasks that require the index to be in a read-only state.

This setting is particularly useful for archival purposes or when you want to ensure data integrity during certain operations. When enabled, it blocks all write operations, including indexing new documents, updating existing documents, and deleting documents.

Example Usage

To set an index to read-only:

PUT /my_index/_settings
{
  "index": {
    "blocks": {
      "read_only": true
    }
  }
}

You might want to change this setting when:

  • Archiving old data that should not be modified
  • Performing maintenance tasks that require data immutability
  • Protecting against accidental writes in a production environment

The effect of this change is immediate: all write operations to the index will be rejected until the setting is reverted.

Common Issues and Misuses

  • Forgetting to disable the read-only mode after maintenance, leading to unexpected indexing failures
  • Applying read-only to indices that require frequent updates
  • Not considering this setting when troubleshooting indexing issues

Do's and Don'ts

Do's:

  • Use this setting for archival indices
  • Enable it during maintenance operations that require data immutability
  • Remember to disable it when write operations need to resume
  • Monitor indices with this setting enabled to ensure it's not causing unexpected issues

Don'ts:

  • Don't leave indices in read-only mode indefinitely unless intended
  • Avoid enabling this on indices that require frequent updates
  • Don't use this as a primary method for access control (use proper security measures instead)

Frequently Asked Questions

Q: How do I check if an index is in read-only mode?
A: You can check the index settings using the GET /{index_name}/_settings API call and look for the "index.blocks.read_only" value.

Q: Can I still search an index when it's in read-only mode?
A: Yes, read operations including searches are still allowed when an index is in read-only mode.

Q: Will setting index.blocks.read_only to true affect other indices?
A: No, this setting is index-specific and will only affect the index it's applied to.

Q: How can I revert an index from read-only back to writable?
A: You can set "index.blocks.read_only" to false using the same PUT /{index_name}/_settings API call.

Q: Is there a difference between index.blocks.read_only and index.blocks.read_only_allow_delete?
A: Yes, index.blocks.read_only_allow_delete allows delete operations while still blocking write and update operations, whereas index.blocks.read_only blocks all write operations including deletes.

Pulse - Elasticsearch Operations Done Right

Stop googling errors and staring at dashboards.

Free Trial

Subscribe to the Pulse Newsletter

Get early access to new Pulse features, insightful blogs & exclusive events , webinars, and workshops.