Skip to content

Commit 8476bb8

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 ed19090 commit 8476bb8

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-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
@@ -299,15 +299,16 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
299299
@Override
300300
protected void doMerge(Mapper mergeWith, boolean updateAllTypes) {
301301
ParentFieldMapper fieldMergeWith = (ParentFieldMapper) mergeWith;
302-
ParentFieldType currentFieldType = (ParentFieldType) fieldType.clone();
303-
super.doMerge(mergeWith, updateAllTypes);
304302
if (fieldMergeWith.parentType != null && Objects.equals(parentType, fieldMergeWith.parentType) == false) {
305303
throw new IllegalArgumentException("The _parent field's type option can't be changed: [" + parentType + "]->[" + fieldMergeWith.parentType + "]");
306304
}
307-
308-
if (active()) {
309-
fieldType = currentFieldType;
305+
// If fieldMergeWith is not active it means the user provided a mapping
306+
// update that does not explicitly configure the _parent field, so we
307+
// ignore it.
308+
if (fieldMergeWith.active()) {
309+
super.doMerge(mergeWith, updateAllTypes);
310310
}
311+
311312
}
312313

313314
/**

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

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

44+
import java.io.IOException;
45+
import java.util.Collection;
4446
import java.util.Collections;
4547
import java.util.HashSet;
4648
import java.util.Set;
@@ -171,4 +173,24 @@ public void testPost2Dot0EagerLoading() {
171173
private static Settings post2Dot0IndexSettings() {
172174
return Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_1_0).build();
173175
}
176+
177+
public void testUpdateEagerGlobalOrds() throws IOException {
178+
String parentMapping = XContentFactory.jsonBuilder().startObject().startObject("parent_type")
179+
.endObject().endObject().string();
180+
String childMapping = XContentFactory.jsonBuilder().startObject().startObject("child_type")
181+
.startObject("_parent").field("type", "parent_type").endObject()
182+
.endObject().endObject().string();
183+
IndexService indexService = createIndex("test", Settings.builder().put("index.version.created", Version.V_5_6_0).build());
184+
indexService.mapperService().merge("parent_type", new CompressedXContent(parentMapping), MergeReason.MAPPING_UPDATE, false);
185+
indexService.mapperService().merge("child_type", new CompressedXContent(childMapping), MergeReason.MAPPING_UPDATE, false);
186+
187+
assertTrue(indexService.mapperService().documentMapper("child_type").parentFieldMapper().fieldType().eagerGlobalOrdinals());
188+
189+
String childMappingUpdate = XContentFactory.jsonBuilder().startObject().startObject("child_type")
190+
.startObject("_parent").field("type", "parent_type").field("eager_global_ordinals", false).endObject()
191+
.endObject().endObject().string();
192+
indexService.mapperService().merge("child_type", new CompressedXContent(childMappingUpdate), MergeReason.MAPPING_UPDATE, false);
193+
194+
assertFalse(indexService.mapperService().documentMapper("child_type").parentFieldMapper().fieldType().eagerGlobalOrdinals());
195+
}
174196
}

0 commit comments

Comments
 (0)