Updating number_of_replicas to for indices – How to solve related issues

Opster Team

Jan-20, Version: 1.7-8.0

Before you begin reading this guide, we recommend you run the Elasticsearch Error Check-Up which can resolve issues that cause many errors.

This guide will help help you understand why the log “Updating number_of_replicas to for indices” has appeared and how to resolve it. It’s also important to understand the issues related to the log, so you can read the general overview on common issues and tips related to these Elasticsearch concepts below: allocation, cluster, indices and routing.

<

Overview

Elasticsearch replica shards can be updated dynamically both manually (by hitting API) or dynamically (based on the number of nodes and configuration) in order to improve search latency. A change in the number of replicas is a critical event, and Elasticsearch logs this event as below:

updating number_of_replicas to {new replicas number} for indices {affected indices list}.

Manual update 

Using Index update setting for existing indices or Index template for a future index. You can update the replica count of an existing index using the update index setting API as shown below. 

PUT /my-index/_settings
{
  "index" : {
    "number_of_replicas" : 2 // replica count
  }
}

Dynamic update 

It’s common to upscale and downscale Elasticsearch clusters based on traffic, and for the same reason, having a fixed number of replicas isn’t very useful in cases like these. That’s why Elasticsearch came up with the concept of index.auto_expand_replicas(default false), which can dynamically increase/decrease the number of replicas based on the configuration and number of nodes in the cluster. 

Example:

If configured (0-5), the number of allocated replicas will match the number of nodes you create. If you increase/decrease, these numbers will also be changed accordingly.

Bottom line: 

This log is solely for information purposes and there’s nothing much to worry about with them, but if it changes without your knowledge, there is a scope to of appropriate actions to take, such as:

Changing the index template to make sure all future indices are not created with fixed settings,

Or:

index.auto_expand_replicas : false

Log Context

Log “Updating number_of_replicas to [{}] for indices {}” classname is AllocationService.java.
We extracted the following from Elasticsearch source code for those seeking an in-depth context :

                     final IndexMetaData indexMetaData = metaDataBuilder.get(index);
                    final IndexMetaData.Builder indexMetaDataBuilder =
                            new IndexMetaData.Builder(indexMetaData).settingsVersion(1 + indexMetaData.getSettingsVersion());
                    metaDataBuilder.put(indexMetaDataBuilder);
                }
                logger.info("updating number_of_replicas to [{}] for indices {}"; numberOfReplicas; indices);
            }
            final ClusterState fixedState = ClusterState.builder(clusterState).routingTable(routingTableBuilder.build())
                .metaData(metaDataBuilder).build();
            assert AutoExpandReplicas.getAutoExpandReplicaChanges(fixedState.metaData(); fixedState.nodes()).isEmpty();
            return fixedState;




 

Watch product tour

Try AutoOps to find & fix Elasticsearch problems

Analyze Your Cluster
Skip to content