@@ -1656,23 +1656,11 @@ static void prepareResizeIndexSettings(
1656
1656
throw new IllegalStateException ("unknown resize type is " + type );
1657
1657
}
1658
1658
1659
- final Settings .Builder builder = Settings . builder () ;
1659
+ final Settings .Builder builder ;
1660
1660
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 );
1675
1662
} else {
1663
+ builder = Settings .builder ();
1676
1664
final Predicate <String > sourceSettingsPredicate = (s ) -> (s .startsWith ("index.similarity." )
1677
1665
|| s .startsWith ("index.analysis." )
1678
1666
|| s .startsWith ("index.sort." )
@@ -1690,6 +1678,36 @@ static void prepareResizeIndexSettings(
1690
1678
}
1691
1679
}
1692
1680
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
+
1693
1711
/**
1694
1712
* Returns a default number of routing shards based on the number of shards of the index. The default number of routing shards will
1695
1713
* 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