@@ -1675,23 +1675,11 @@ static void prepareResizeIndexSettings(
16751675 throw  new  IllegalStateException ("unknown resize type is "  + type );
16761676 }
16771677
1678-  final  Settings .Builder  builder  =  Settings . builder () ;
1678+  final  Settings .Builder  builder ;
16791679 if  (copySettings ) {
1680-  // copy all settings and non-copyable settings and settings that have already been set (e.g., from the request) 
1681-  for  (final  String  key  : sourceMetadata .getSettings ().keySet ()) {
1682-  final  Setting <?> setting  = indexScopedSettings .get (key );
1683-  if  (setting  == null ) {
1684-  assert  indexScopedSettings .isPrivateSetting (key ) : key ;
1685-  } else  if  (setting .getProperties ().contains (Setting .Property .NotCopyableOnResize )) {
1686-  continue ;
1687-  }
1688-  // do not override settings that have already been set (for example, from the request) 
1689-  if  (indexSettingsBuilder .keys ().contains (key )) {
1690-  continue ;
1691-  }
1692-  builder .copy (key , sourceMetadata .getSettings ());
1693-  }
1680+  builder  = copySettingsFromSource (true , sourceMetadata .getSettings (), indexScopedSettings , indexSettingsBuilder );
16941681 } else  {
1682+  builder  = Settings .builder ();
16951683 final  Predicate <String > sourceSettingsPredicate  = (s ) -> (s .startsWith ("index.similarity." )
16961684 || s .startsWith ("index.analysis." )
16971685 || s .startsWith ("index.sort." )
@@ -1709,6 +1697,36 @@ static void prepareResizeIndexSettings(
17091697 }
17101698 }
17111699
1700+  public  static  Settings .Builder  copySettingsFromSource (
1701+  boolean  copyPrivateSettings ,
1702+  Settings  sourceSettings ,
1703+  IndexScopedSettings  indexScopedSettings ,
1704+  Settings .Builder  indexSettingsBuilder 
1705+  ) {
1706+  final  Settings .Builder  builder  = Settings .builder ();
1707+  for  (final  String  key  : sourceSettings .keySet ()) {
1708+  final  Setting <?> setting  = indexScopedSettings .get (key );
1709+  if  (setting  == null ) {
1710+  assert  indexScopedSettings .isPrivateSetting (key ) : key ;
1711+  if  (copyPrivateSettings  == false ) {
1712+  continue ;
1713+  }
1714+  } else  if  (setting .getProperties ().contains (Setting .Property .NotCopyableOnResize )) {
1715+  continue ;
1716+  } else  if  (setting .isPrivateIndex ()) {
1717+  if  (copyPrivateSettings  == false ) {
1718+  continue ;
1719+  }
1720+  }
1721+  // do not override settings that have already been set (for example, from the request) 
1722+  if  (indexSettingsBuilder .keys ().contains (key )) {
1723+  continue ;
1724+  }
1725+  builder .copy (key , sourceSettings );
1726+  }
1727+  return  builder ;
1728+  }
1729+ 
17121730 /** 
17131731 * Returns a default number of routing shards based on the number of shards of the index. The default number of routing shards will 
17141732 * allow any index to be split at least once and at most 10 times by a factor of two. The closer the number or shards gets to 1024 
0 commit comments