@@ -366,8 +366,15 @@ public ClusterState execute(ClusterState currentState) throws Exception {
366
366
}
367
367
// now, put the request settings, so they override templates
368
368
indexSettingsBuilder .put (request .settings ());
369
+ if (indexSettingsBuilder .get (SETTING_VERSION_CREATED ) == null ) {
370
+ DiscoveryNodes nodes = currentState .nodes ();
371
+ final Version createdVersion = Version .min (Version .CURRENT , nodes .getSmallestNonClientNodeVersion ());
372
+ indexSettingsBuilder .put (SETTING_VERSION_CREATED , createdVersion );
373
+ }
369
374
if (indexSettingsBuilder .get (SETTING_NUMBER_OF_SHARDS ) == null ) {
370
- indexSettingsBuilder .put (SETTING_NUMBER_OF_SHARDS , settings .getAsInt (SETTING_NUMBER_OF_SHARDS , 1 ));
375
+ final int numberOfShards = getNumberOfShards (indexSettingsBuilder );
376
+
377
+ indexSettingsBuilder .put (SETTING_NUMBER_OF_SHARDS , settings .getAsInt (SETTING_NUMBER_OF_SHARDS , numberOfShards ));
371
378
}
372
379
if (indexSettingsBuilder .get (SETTING_NUMBER_OF_REPLICAS ) == null ) {
373
380
indexSettingsBuilder .put (SETTING_NUMBER_OF_REPLICAS , settings .getAsInt (SETTING_NUMBER_OF_REPLICAS , 1 ));
@@ -376,12 +383,6 @@ public ClusterState execute(ClusterState currentState) throws Exception {
376
383
indexSettingsBuilder .put (SETTING_AUTO_EXPAND_REPLICAS , settings .get (SETTING_AUTO_EXPAND_REPLICAS ));
377
384
}
378
385
379
- if (indexSettingsBuilder .get (SETTING_VERSION_CREATED ) == null ) {
380
- DiscoveryNodes nodes = currentState .nodes ();
381
- final Version createdVersion = Version .min (Version .CURRENT , nodes .getSmallestNonClientNodeVersion ());
382
- indexSettingsBuilder .put (SETTING_VERSION_CREATED , createdVersion );
383
- }
384
-
385
386
if (indexSettingsBuilder .get (SETTING_CREATION_DATE ) == null ) {
386
387
indexSettingsBuilder .put (SETTING_CREATION_DATE , new DateTime (DateTimeZone .UTC ).getMillis ());
387
388
}
@@ -573,6 +574,18 @@ public ClusterState execute(ClusterState currentState) throws Exception {
573
574
}
574
575
}
575
576
577
+ static int getNumberOfShards (Settings .Builder indexSettingsBuilder ) {
578
+ // TODO: this logic can be removed when the current major version is 8
579
+ assert Version .CURRENT .major == 7 ;
580
+ final int numberOfShards ;
581
+ if (Version .fromId (Integer .parseInt (indexSettingsBuilder .get (SETTING_VERSION_CREATED ))).before (Version .V_7_0_0_alpha1 )) {
582
+ numberOfShards = 5 ;
583
+ } else {
584
+ numberOfShards = 1 ;
585
+ }
586
+ return numberOfShards ;
587
+ }
588
+
576
589
@ Override
577
590
public void onFailure (String source , Exception e ) {
578
591
if (e instanceof ResourceAlreadyExistsException ) {
0 commit comments