Skip to content

Commit 18a6888

Browse files
committed
Match dot prefix of migrated index with the source index
1 parent d3a1d9b commit 18a6888

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

x-pack/plugin/migrate/src/internalClusterTest/java/org/elasticsearch/xpack/migrate/action/ReindexDatastreamIndexTransportActionIT.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void testDestIndexDeletedIfExists() throws Exception {
9696
assertHitCount(prepareSearch(destIndex).setSize(0), 0);
9797
}
9898

99-
public void testDestIndexNameSet() throws Exception {
99+
public void testDestIndexNameSet_noDotPrefix() throws Exception {
100100
assumeTrue("requires the migration reindex feature flag", REINDEX_DATA_STREAM_FEATURE_FLAG.isEnabled());
101101

102102
var sourceIndex = randomAlphaOfLength(20).toLowerCase(Locale.ROOT);
@@ -110,6 +110,20 @@ public void testDestIndexNameSet() throws Exception {
110110
assertEquals(expectedDestIndexName, response.getDestIndex());
111111
}
112112

113+
public void testDestIndexNameSet_withDotPrefix() throws Exception {
114+
assumeTrue("requires the migration reindex feature flag", REINDEX_DATA_STREAM_FEATURE_FLAG.isEnabled());
115+
116+
var sourceIndex = "." + randomAlphaOfLength(20).toLowerCase(Locale.ROOT);
117+
indicesAdmin().create(new CreateIndexRequest(sourceIndex)).get();
118+
119+
// call reindex
120+
var response = client().execute(ReindexDataStreamIndexAction.INSTANCE, new ReindexDataStreamIndexAction.Request(sourceIndex))
121+
.actionGet();
122+
123+
var expectedDestIndexName = ReindexDataStreamIndexTransportAction.generateDestIndexName(sourceIndex);
124+
assertEquals(expectedDestIndexName, response.getDestIndex());
125+
}
126+
113127
public void testDestIndexContainsDocs() throws Exception {
114128
assumeTrue("requires the migration reindex feature flag", REINDEX_DATA_STREAM_FEATURE_FLAG.isEnabled());
115129

@@ -446,4 +460,32 @@ private static String getIndexUUID(String index) {
446460
.get(index)
447461
.get(IndexMetadata.SETTING_INDEX_UUID);
448462
}
463+
464+
public void testGenerateDestIndexName_noDotPrefix() {
465+
String sourceIndex = "sourceindex";
466+
String expectedDestIndex = "migrated-sourceindex";
467+
String actualDestIndex = ReindexDataStreamIndexTransportAction.generateDestIndexName(sourceIndex);
468+
assertEquals(expectedDestIndex, actualDestIndex);
469+
}
470+
471+
public void testGenerateDestIndexName_withDotPrefix() {
472+
String sourceIndex = ".sourceindex";
473+
String expectedDestIndex = ".migrated-sourceindex";
474+
String actualDestIndex = ReindexDataStreamIndexTransportAction.generateDestIndexName(sourceIndex);
475+
assertEquals(expectedDestIndex, actualDestIndex);
476+
}
477+
478+
public void testGenerateDestIndexName_withHyphen() {
479+
String sourceIndex = "source-index";
480+
String expectedDestIndex = "migrated-source-index";
481+
String actualDestIndex = ReindexDataStreamIndexTransportAction.generateDestIndexName(sourceIndex);
482+
assertEquals(expectedDestIndex, actualDestIndex);
483+
}
484+
485+
public void testGenerateDestIndexName_withUnderscore() {
486+
String sourceIndex = "source_index";
487+
String expectedDestIndex = "migrated-source_index";
488+
String actualDestIndex = ReindexDataStreamIndexTransportAction.generateDestIndexName(sourceIndex);
489+
assertEquals(expectedDestIndex, actualDestIndex);
490+
}
449491
}

x-pack/plugin/migrate/src/main/java/org/elasticsearch/xpack/migrate/action/ReindexDataStreamIndexTransportAction.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,12 @@ private static void copySettingOrUnset(Settings settingsBefore, Settings.Builder
221221
}
222222
}
223223

224-
public static String generateDestIndexName(String sourceIndex) {
225-
return "migrated-" + sourceIndex;
224+
static String generateDestIndexName(String sourceIndex) {
225+
String prefix = "migrated-";
226+
if (sourceIndex.startsWith(".")) {
227+
return "." + prefix + sourceIndex.substring(1);
228+
}
229+
return prefix + sourceIndex;
226230
}
227231

228232
private static <U extends AcknowledgedResponse> ActionListener<U> failIfNotAcknowledged(

0 commit comments

Comments
 (0)