Updating Elasticsearch index settings tunes indexing throughput, search freshness, and resilience without recreating an index. Changes to index.number_of_replicas and index.refresh_interval trade off redundancy and near real-time visibility based on workload demands.
Index settings are stored as per-index metadata and are read or changed through the /_settings endpoint. Dynamic settings apply to open indices immediately, while static settings are only accepted when the index is closed.
Some settings are immutable once an index is created (for example index.number_of_shards) and require creating a new index plus reindexing to change. Reducing replicas lowers fault tolerance, increasing replicas can leave shards unassigned until enough data nodes exist, and longer refresh intervals delay when new documents appear in search. Secure clusters require https plus authentication and may also require a trusted CA certificate for API calls.
Steps to update index settings in Elasticsearch:
- List the target index to confirm the exact index name.
$ curl -s "http://localhost:9200/_cat/indices/logs-2025.01?v" health status index uuid pri rep docs.count docs.deleted store.size pri.store.size dataset.size green open logs-2025.01 98GlrCaeQae_bXpWVIp22g 1 0 3 0 23.9kb 23.9kb 23.9kb
- Review the current settings for the index.
$ curl -s "http://localhost:9200/logs-2025.01/_settings?pretty&filter_path=*.settings.index.number_of_replicas,*.settings.index.refresh_interval" { "logs-2025.01" : { "settings" : { "index" : { "number_of_replicas" : "0" } } } }Secure clusters add curl options such as -u for authentication plus –cacert for TLS.
- Update dynamic index settings for index.number_of_replicas, index.refresh_interval.
$ curl -s -H "Content-Type: application/json" -X PUT "http://localhost:9200/logs-2025.01/_settings?pretty" -d '{ "index": { "number_of_replicas": 2, "refresh_interval": "30s" } }' { "acknowledged" : true }Reducing index.number_of_replicas lowers redundancy; setting 0 removes replica failover for primaries.
Setting index.refresh_interval to -1 disables automatic refresh during bulk indexing. Replica increases can leave shards UNASSIGNED until enough data nodes exist. Setting a value to null resets that setting to the default. Index patterns such as logs-2025.* can target multiple indices.
- Verify the updated settings.
$ curl -s "http://localhost:9200/logs-2025.01/_settings?pretty&filter_path=*.settings.index.number_of_replicas,*.settings.index.refresh_interval" { "logs-2025.01" : { "settings" : { "index" : { "refresh_interval" : "30s", "number_of_replicas" : "2" } } } } - Check index health to confirm shard allocation is stable.
$ curl -s "http://localhost:9200/_cluster/health/logs-2025.01?pretty" { "cluster_name" : "search-cluster", "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" : 2, "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" : 33.33333333333333 } - Confirm primary and replica shards are started for the index.
$ curl -s "http://localhost:9200/_cat/shards/logs-2025.01?v" index shard prirep state docs store dataset ip node logs-2025.01 0 p STARTED 3 23.9kb 23.9kb 192.0.2.40 node-01 logs-2025.01 0 r UNASSIGNED logs-2025.01 0 r UNASSIGNED
Replica rows show r in the prirep column.
- Close the index when a static setting change is required.
$ curl -s -X POST "http://localhost:9200/logs-2025.01/_close?pretty" { "acknowledged" : true, "shards_acknowledged" : true, "indices" : { "logs-2025.01" : { "closed" : true } } }A closed index is unavailable for search or indexing until reopened.
- Update a static index setting on the closed index.
$ curl -s -H "Content-Type: application/json" -X PUT "http://localhost:9200/logs-2025.01/_settings?pretty" -d '{ "index": { "codec": "best_compression" } }' { "acknowledged" : true }Changing index.codec affects newly written segments; existing segments require merging to be rewritten with the new codec.
- Open the index to restore access.
$ curl -s -X POST "http://localhost:9200/logs-2025.01/_open?pretty" { "acknowledged" : true, "shards_acknowledged" : true } - Verify the static setting value.
$ curl -s "http://localhost:9200/logs-2025.01/_settings?pretty&filter_path=*.settings.index.codec" { "logs-2025.01" : { "settings" : { "index" : { "codec" : "best_compression" } } } }
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
