@@ -1656,23 +1656,11 @@ static void prepareResizeIndexSettings(
16561656 throw new IllegalStateException ("unknown resize type is " + type );
16571657 }
16581658
1659- final Settings .Builder builder = Settings . builder () ;
1659+ final Settings .Builder builder ;
16601660 if (copySettings ) {
1661- // copy all settings and non-copyable settings and settings that have already been set (e.g., from the request)
1662- for (final String key : sourceMetadata .getSettings ().keySet ()) {
1663- final Setting <?> setting = indexScopedSettings .get (key );
1664- if (setting == null ) {
1665- assert indexScopedSettings .isPrivateSetting (key ) : key ;
1666- } else if (setting .getProperties ().contains (Setting .Property .NotCopyableOnResize )) {
1667- continue ;
1668- }
1669- // do not override settings that have already been set (for example, from the request)
1670- if (indexSettingsBuilder .keys ().contains (key )) {
1671- continue ;
1672- }
1673- builder .copy (key , sourceMetadata .getSettings ());
1674- }
1661+ builder = copySettingsFromSource (true , sourceMetadata .getSettings (), indexScopedSettings , indexSettingsBuilder );
16751662 } else {
1663+ builder = Settings .builder ();
16761664 final Predicate <String > sourceSettingsPredicate = (s ) -> (s .startsWith ("index.similarity." )
16771665 || s .startsWith ("index.analysis." )
16781666 || s .startsWith ("index.sort." )
@@ -1690,6 +1678,36 @@ static void prepareResizeIndexSettings(
16901678 }
16911679 }
16921680
1681+ public static Settings .Builder copySettingsFromSource (
1682+ boolean copyPrivateSettings ,
1683+ Settings sourceSettings ,
1684+ IndexScopedSettings indexScopedSettings ,
1685+ Settings .Builder indexSettingsBuilder
1686+ ) {
1687+ final Settings .Builder builder = Settings .builder ();
1688+ for (final String key : sourceSettings .keySet ()) {
1689+ final Setting <?> setting = indexScopedSettings .get (key );
1690+ if (setting == null ) {
1691+ assert indexScopedSettings .isPrivateSetting (key ) : key ;
1692+ if (copyPrivateSettings == false ) {
1693+ continue ;
1694+ }
1695+ } else if (setting .getProperties ().contains (Setting .Property .NotCopyableOnResize )) {
1696+ continue ;
1697+ } else if (setting .isPrivateIndex ()) {
1698+ if (copyPrivateSettings == false ) {
1699+ continue ;
1700+ }
1701+ }
1702+ // do not override settings that have already been set (for example, from the request)
1703+ if (indexSettingsBuilder .keys ().contains (key )) {
1704+ continue ;
1705+ }
1706+ builder .copy (key , sourceSettings );
1707+ }
1708+ return builder ;
1709+ }
1710+
16931711 /**
16941712 * Returns a default number of routing shards based on the number of shards of the index. The default number of routing shards will
16951713 * 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