@@ -140,6 +140,7 @@ public void updateSettings(
140
140
141
141
validateRefreshIntervalSettings (normalizedSettings , clusterService .getClusterSettings ());
142
142
validateTranslogDurabilitySettings (normalizedSettings , clusterService .getClusterSettings (), clusterService .getSettings ());
143
+ final int defaultReplicaCount = clusterService .getClusterSettings ().get (Metadata .DEFAULT_REPLICA_COUNT_SETTING );
143
144
144
145
Settings .Builder settingsForClosedIndices = Settings .builder ();
145
146
Settings .Builder settingsForOpenIndices = Settings .builder ();
@@ -248,7 +249,10 @@ public ClusterState execute(ClusterState currentState) {
248
249
}
249
250
250
251
if (IndexMetadata .INDEX_NUMBER_OF_REPLICAS_SETTING .exists (openSettings )) {
251
- final int updatedNumberOfReplicas = IndexMetadata .INDEX_NUMBER_OF_REPLICAS_SETTING .get (openSettings );
252
+ final int updatedNumberOfReplicas = openSettings .getAsInt (
253
+ IndexMetadata .SETTING_NUMBER_OF_REPLICAS ,
254
+ defaultReplicaCount
255
+ );
252
256
if (preserveExisting == false ) {
253
257
for (Index index : request .indices ()) {
254
258
if (index .getName ().charAt (0 ) != '.' ) {
@@ -329,15 +333,13 @@ public ClusterState execute(ClusterState currentState) {
329
333
/*
330
334
* The setting index.number_of_replicas is special; we require that this setting has a value in the index. When
331
335
* creating the index, we ensure this by explicitly providing a value for the setting to the default (one) if
332
- * there is a not value provided on the source of the index creation. A user can update this setting though,
333
- * including updating it to null, indicating that they want to use the default value. In this case, we again
334
- * have to provide an explicit value for the setting to the default (one).
336
+ * there is no value provided on the source of the index creation or "cluster.default_number_of_replicas" is
337
+ * not set. A user can update this setting though, including updating it to null, indicating that they want to
338
+ * use the value configured by cluster settings or a default value 1. In this case, we again have to provide
339
+ * an explicit value for the setting.
335
340
*/
336
341
if (IndexMetadata .INDEX_NUMBER_OF_REPLICAS_SETTING .exists (indexSettings ) == false ) {
337
- indexSettings .put (
338
- IndexMetadata .SETTING_NUMBER_OF_REPLICAS ,
339
- IndexMetadata .INDEX_NUMBER_OF_REPLICAS_SETTING .get (Settings .EMPTY )
340
- );
342
+ indexSettings .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , defaultReplicaCount );
341
343
}
342
344
Settings finalSettings = indexSettings .build ();
343
345
indexScopedSettings .validate (
0 commit comments