Skip to content

Commit e4b001b

Browse files
parkertimminsmaxhniebergall
authored andcommitted
Add ReindexDatastreamIndexAction (elastic#116996) (elastic#118703)
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. (cherry picked from commit 0a6ce27)
1 parent 6eecf91 commit e4b001b

File tree

10 files changed

+841
-16
lines changed

10 files changed

+841
-16
lines changed

docs/changelog/116996.yaml

+5
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

+33-15
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)