Skip to content

Commit 0a6ce27

Browse files
Add ReindexDatastreamIndexAction (elastic#116996)
Add an action to reindex a single index from a source index to a destination index. Unlike the reindex action, this action copies settings and mappings from the source index to the dest index before performing the reindex. This action is part of work to reindex data streams and will be called on each of the backing indices within a data stream.
1 parent b4610c8 commit 0a6ce27

File tree

10 files changed

+841
-16
lines changed

10 files changed

+841
-16
lines changed

docs/changelog/116996.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 116996
2+
summary: Initial work on `ReindexDatastreamIndexAction`
3+
area: Data streams
4+
type: enhancement
5+
issues: []

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)