Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ public void merge(Mapper mergeWith, MergeResult mergeResult) throws MergeMapping
ParentFieldMapper fieldMergeWith = (ParentFieldMapper) mergeWith;
if (Objects.equals(parentType, fieldMergeWith.parentType) == false) {
mergeResult.addConflict("The _parent field's type option can't be changed: [" + parentType + "]->[" + fieldMergeWith.parentType + "]");
return;
}

List<String> conflicts = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.elasticsearch.index.mapper.ContentPath;
import org.elasticsearch.index.mapper.MappedFieldType.Loading;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MergeResult;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.test.ESTestCase;

import static org.elasticsearch.common.settings.Settings.settingsBuilder;
Expand Down Expand Up @@ -143,6 +145,25 @@ public void testPre2Dot0EagerGlobalOrdinalsLoading() {
assertThat(parentFieldMapper.getChildJoinFieldType().docValuesType(), equalTo(DocValuesType.NONE));
}

public void testMergeWithDefaultParentField() {
Settings indexSettings = post2Dot0IndexSettings();
ParentFieldMapper.Builder builder = new ParentFieldMapper.Builder("child");
builder.type("parent");
ParentFieldMapper fieldMapper = builder.build(new Mapper.BuilderContext(indexSettings, new ContentPath(0)));

IndicesModule indicesModule = new IndicesModule();
ParentFieldMapper otherFieldMapper = (ParentFieldMapper) indicesModule.getMapperRegistry().getMetadataMapperParsers()
.get(ParentFieldMapper.NAME)
.getDefault(indexSettings, ParentFieldMapper.Defaults.FIELD_TYPE, ParentFieldMapper.NAME);

MergeResult mergeResult = new MergeResult(false, false);
fieldMapper.merge(otherFieldMapper, mergeResult);
assertThat(mergeResult.hasConflicts(), is(true));
String[] buildConflicts = mergeResult.buildConflicts();
assertThat(buildConflicts.length, equalTo(1));
assertThat(buildConflicts[0], equalTo("The _parent field's type option can't be changed: [parent]->[null]"));
}

private static Settings pre2Dot0IndexSettings() {
return Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_6_3).build();
}
Expand Down