diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_6_8_to_OS_2_11.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_6_8_to_OS_2_11.java index 5a2c4325b..452dac09e 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_6_8_to_OS_2_11.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_6_8_to_OS_2_11.java @@ -38,8 +38,16 @@ public GlobalMetadata transformGlobalMetadata(GlobalMetadata globalData) { templatesRoot.fields().forEachRemaining(template -> { var templateCopy = (ObjectNode) template.getValue().deepCopy(); var indexTemplate = (Index) () -> templateCopy; - transformIndex(indexTemplate, IndexType.TEMPLATE); - templates.set(template.getKey(), indexTemplate.getRawJson()); + try { + transformIndex(indexTemplate, IndexType.TEMPLATE); + templates.set(template.getKey(), indexTemplate.getRawJson()); + } catch (Exception e) { + log.atError() + .setMessage("Unable to transform object: {}") + .addArgument(indexTemplate::getRawJson) + .setCause(e) + .log(); + } }); newRoot.set("templates", templates); } diff --git a/transformation/src/main/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemoval.java b/transformation/src/main/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemoval.java index 0de9dca72..833d1f13d 100644 --- a/transformation/src/main/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemoval.java +++ b/transformation/src/main/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemoval.java @@ -45,7 +45,7 @@ public class IndexMappingTypeRemoval implements TransformationRule { public CanApplyResult canApply(final Index index) { final var mappingNode = index.getRawJson().get(MAPPINGS_KEY); - if (mappingNode == null) { + if (mappingNode == null || mappingNode.size() == 0) { return CanApplyResult.NO; } diff --git a/transformation/src/test/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemovalTest.java b/transformation/src/test/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemovalTest.java index f1c74b996..6262dd2c9 100644 --- a/transformation/src/test/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemovalTest.java +++ b/transformation/src/test/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemovalTest.java @@ -120,6 +120,21 @@ private boolean applyTransformation(final ObjectNode indexJson) { return wasChanged; } + @Test + void testApplyTransformation_emptyMappingArray() { + // Setup + var originalJson = indexSettingJson("\"mappings\": [],"); + var indexJson = originalJson.deepCopy(); + + // Action + var wasChanged = applyTransformation(indexJson); + assertThat(canApply(originalJson), equalTo(CanApplyResult.NO)); + + // Verification + assertThat(wasChanged, equalTo(false)); + assertThat(indexJson.toPrettyString(), equalTo(originalJson.toPrettyString())); + } + @Test void testApplyTransformation_noMappingNode() { // Setup