Skip to content

Commit

Permalink
Allow update of eager_global_ordinals on _parent. (#28014)
Browse files Browse the repository at this point in the history
A bug introduced in #24407 currently prevents `eager_global_ordinals` from
being updated. This new approach should fix the issue while still allowing
mapping updates to not specify the `_parent` field if it doesn't need
updating, which was the goal of #24407.
  • Loading branch information
jpountz authored Jan 15, 2018
1 parent bd11e6c commit 77a7e24
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,16 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
@Override
protected void doMerge(Mapper mergeWith, boolean updateAllTypes) {
ParentFieldMapper fieldMergeWith = (ParentFieldMapper) mergeWith;
ParentFieldType currentFieldType = (ParentFieldType) fieldType.clone();
super.doMerge(mergeWith, updateAllTypes);
if (fieldMergeWith.parentType != null && Objects.equals(parentType, fieldMergeWith.parentType) == false) {
throw new IllegalArgumentException("The _parent field's type option can't be changed: [" + parentType + "]->[" + fieldMergeWith.parentType + "]");
}

if (active()) {
fieldType = currentFieldType;
// If fieldMergeWith is not active it means the user provided a mapping
// update that does not explicitly configure the _parent field, so we
// ignore it.
if (fieldMergeWith.active()) {
super.doMerge(mergeWith, updateAllTypes);
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.elasticsearch.test.IndexSettingsModule;
import org.elasticsearch.test.InternalSettingsPlugin;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -138,4 +139,23 @@ private static int getNumberOfFieldWithParentPrefix(ParseContext.Document doc) {
return numFieldWithParentPrefix;
}

public void testUpdateEagerGlobalOrds() throws IOException {
String parentMapping = XContentFactory.jsonBuilder().startObject().startObject("parent_type")
.endObject().endObject().string();
String childMapping = XContentFactory.jsonBuilder().startObject().startObject("child_type")
.startObject("_parent").field("type", "parent_type").endObject()
.endObject().endObject().string();
IndexService indexService = createIndex("test", Settings.builder().put("index.version.created", Version.V_5_6_0).build());
indexService.mapperService().merge("parent_type", new CompressedXContent(parentMapping), MergeReason.MAPPING_UPDATE, false);
indexService.mapperService().merge("child_type", new CompressedXContent(childMapping), MergeReason.MAPPING_UPDATE, false);

assertTrue(indexService.mapperService().documentMapper("child_type").parentFieldMapper().fieldType().eagerGlobalOrdinals());

String childMappingUpdate = XContentFactory.jsonBuilder().startObject().startObject("child_type")
.startObject("_parent").field("type", "parent_type").field("eager_global_ordinals", false).endObject()
.endObject().endObject().string();
indexService.mapperService().merge("child_type", new CompressedXContent(childMappingUpdate), MergeReason.MAPPING_UPDATE, false);

assertFalse(indexService.mapperService().documentMapper("child_type").parentFieldMapper().fieldType().eagerGlobalOrdinals());
}
}

0 comments on commit 77a7e24

Please sign in to comment.