Skip to content

Commit ba1ceda

Browse files
committed
Allow update of eager_global_ordinals on _parent. (#28014)
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.
1 parent d2a2a53 commit ba1ceda

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

core/src/main/java/org/elasticsearch/index/mapper/ParentFieldMapper.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,16 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
303303
@Override
304304
protected void doMerge(Mapper mergeWith, boolean updateAllTypes) {
305305
ParentFieldMapper fieldMergeWith = (ParentFieldMapper) mergeWith;
306-
ParentFieldType currentFieldType = (ParentFieldType) fieldType.clone();
307-
super.doMerge(mergeWith, updateAllTypes);
308306
if (fieldMergeWith.parentType != null && Objects.equals(parentType, fieldMergeWith.parentType) == false) {
309307
throw new IllegalArgumentException("The _parent field's type option can't be changed: [" + parentType + "]->[" + fieldMergeWith.parentType + "]");
310308
}
311-
312-
if (active()) {
313-
fieldType = currentFieldType;
309+
// If fieldMergeWith is not active it means the user provided a mapping
310+
// update that does not explicitly configure the _parent field, so we
311+
// ignore it.
312+
if (fieldMergeWith.active()) {
313+
super.doMerge(mergeWith, updateAllTypes);
314314
}
315+
315316
}
316317

317318
/**

core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.elasticsearch.test.IndexSettingsModule;
4242
import org.elasticsearch.test.InternalSettingsPlugin;
4343

44+
import java.io.IOException;
4445
import java.util.Collection;
4546
import java.util.Collections;
4647
import java.util.HashSet;
@@ -138,4 +139,23 @@ private static int getNumberOfFieldWithParentPrefix(ParseContext.Document doc) {
138139
return numFieldWithParentPrefix;
139140
}
140141

142+
public void testUpdateEagerGlobalOrds() throws IOException {
143+
String parentMapping = XContentFactory.jsonBuilder().startObject().startObject("parent_type")
144+
.endObject().endObject().string();
145+
String childMapping = XContentFactory.jsonBuilder().startObject().startObject("child_type")
146+
.startObject("_parent").field("type", "parent_type").endObject()
147+
.endObject().endObject().string();
148+
IndexService indexService = createIndex("test", Settings.builder().put("index.version.created", Version.V_5_6_0).build());
149+
indexService.mapperService().merge("parent_type", new CompressedXContent(parentMapping), MergeReason.MAPPING_UPDATE, false);
150+
indexService.mapperService().merge("child_type", new CompressedXContent(childMapping), MergeReason.MAPPING_UPDATE, false);
151+
152+
assertTrue(indexService.mapperService().documentMapper("child_type").parentFieldMapper().fieldType().eagerGlobalOrdinals());
153+
154+
String childMappingUpdate = XContentFactory.jsonBuilder().startObject().startObject("child_type")
155+
.startObject("_parent").field("type", "parent_type").field("eager_global_ordinals", false).endObject()
156+
.endObject().endObject().string();
157+
indexService.mapperService().merge("child_type", new CompressedXContent(childMappingUpdate), MergeReason.MAPPING_UPDATE, false);
158+
159+
assertFalse(indexService.mapperService().documentMapper("child_type").parentFieldMapper().fieldType().eagerGlobalOrdinals());
160+
}
141161
}

0 commit comments

Comments
 (0)