Skip to content

Commit 65cf44f

Browse files
coroRahul De
andcommitted
Add handling of empty mapping string
Co-authored-by: Rahul De <[email protected]>
1 parent 2e4482f commit 65cf44f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

es/resource_elasticsearch_index.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,19 @@ func verifyIndexMappingUpdates(ctx context.Context, resourceDiff *schema.Resourc
754754
if !resourceDiff.HasChange("mappings") {
755755
return nil
756756
}
757+
757758
oldMapping, newMapping := resourceDiff.GetChange("mappings")
758-
difference, _ := jsondiff.Compare([]byte(newMapping.(string)), []byte(oldMapping.(string)), &jsondiff.Options{})
759-
if difference > jsondiff.SupersetMatch {
759+
oldMappingStr := oldMapping.(string)
760+
if len(oldMappingStr) == 0 {
761+
oldMappingStr = "{}"
762+
}
763+
newMappingStr := newMapping.(string)
764+
if len(newMappingStr) == 0 {
765+
newMappingStr = "{}"
766+
}
767+
difference, _ := jsondiff.Compare([]byte(newMappingStr), []byte(oldMappingStr), &jsondiff.Options{})
768+
// The new mapping is not a superset of the old mapping, therefore the index requires recreation
769+
if difference == jsondiff.NoMatch {
760770
return resourceDiff.ForceNew("mappings")
761771
}
762772
return nil

0 commit comments

Comments
 (0)