Briefly, this error occurs when there’s an attempt to update the number of replicas for indices in Elasticsearch, but the new number is not specified or is invalid. This could be due to a syntax error or a misconfiguration. To resolve this issue, ensure that the number of replicas is correctly specified and is a valid integer. Also, check the cluster health and ensure that there are enough nodes to accommodate the new number of replicas. If not, add more nodes or reduce the number of replicas.
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
Overview
In Elasticsearch, routing refers to document routing. When you index a document, Elasticsearch will determine which shard the document should be routed to for indexing.
The shard is selected based on the following formula:
shard = hash(_routing) % number_of_primary_shards
Where the default value of _routing is _id.
It is important to know which shard the document is routed to, because Elasticsearch will need to determine where to find that document later on for document retrieval requests.
Examples
In twitter index with 2 primary shards, the document with _id equal to “440” gets routed to the shard number:
shard = hash( 440 ) % 2 PUT twitter/_doc/440 { ... }
Notes and good things to know
- In order to improve search speed, you can create custom routing. For example, you can enable custom routing that will ensure that only a single shard will be queried (the shard that contains your data).
- To create custom routing in Elasticsearch, you will need to configure and define that not all routing will be completed by default settings. ( v <= 5.0)
PUT my_index/customer/_mapping { "order":{ "_routing":{ "required":true } } }
- This will ensure that every document in the “customer” type must specify a custom routing. For Elasticsearch version 6 or above you will need to update the same mapping as:
PUT my_index/_mapping { "order":{ "_routing":{ "required":true } } }
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.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();
[ratemypost]