Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not lose default mapper on metadata updates #33153

Merged
merged 2 commits into from
Aug 26, 2018
Merged
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 @@ -468,11 +468,11 @@ private synchronized Map<String, DocumentMapper> internalMerge(@Nullable Documen
// commit the change
if (defaultMappingSource != null) {
this.defaultMappingSource = defaultMappingSource;
this.defaultMapper = defaultMapper;
}
if (newMapper != null) {
this.mapper = newMapper;
}
this.defaultMapper = defaultMapper;
this.fieldTypes = fieldTypes;
this.hasNested = hasNested;
this.fullPathObjectMappers = fullPathObjectMappers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@

import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType;
import org.elasticsearch.index.mapper.MapperService.MergeReason;
Expand Down Expand Up @@ -119,6 +122,35 @@ public void testIndexIntoDefaultMapping() throws Throwable {
assertNull(indexService.mapperService().documentMapper(MapperService.DEFAULT_MAPPING));
}

public void testIndexMetaDataUpdateDoesNotLoseDefaultMapper() throws IOException {
final IndexService indexService =
createIndex("test", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_6_3_0).build());
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
builder.startObject();
{
builder.startObject(MapperService.DEFAULT_MAPPING);
{
builder.field("date_detection", false);
}
builder.endObject();
}
builder.endObject();
final PutMappingRequest putMappingRequest = new PutMappingRequest();
putMappingRequest.indices("test");
putMappingRequest.type(MapperService.DEFAULT_MAPPING);
putMappingRequest.source(builder);
client().admin().indices().preparePutMapping("test").setType(MapperService.DEFAULT_MAPPING).setSource(builder).get();
}
assertNotNull(indexService.mapperService().documentMapper(MapperService.DEFAULT_MAPPING));
final Settings zeroReplicasSettings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build();
client().admin().indices().prepareUpdateSettings("test").setSettings(zeroReplicasSettings).get();
/*
* This assertion is a guard against a previous bug that would lose the default mapper when applying a metadata update that did not
* update the default mapping.
*/
assertNotNull(indexService.mapperService().documentMapper(MapperService.DEFAULT_MAPPING));
}

public void testTotalFieldsExceedsLimit() throws Throwable {
Function<String, String> mapping = type -> {
try {
Expand Down