Skip to content

Commit

Permalink
Fix bug handle empty mappings when removing mapping types
Browse files Browse the repository at this point in the history
- Resolves #1177

Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Dec 4, 2024
1 parent d7889c3 commit e1e03d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class IndexMappingTypeRemoval implements TransformationRule<Index> {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e1e03d0

Please sign in to comment.