Merge pull request #16023 from jpountz/fix/implicit_self_conflict

Reuse metadata mappers for dynamic updates.
This commit is contained in:
Adrien Grand 2016-01-19 09:28:04 +01:00
commit a90d2fa0b4
2 changed files with 37 additions and 2 deletions

View File

@ -79,10 +79,20 @@ public class DocumentMapper implements ToXContent {
this.builderContext = new Mapper.BuilderContext(indexSettings, new ContentPath(1));
this.rootObjectMapper = builder.build(builderContext);
final String type = rootObjectMapper.name();
DocumentMapper existingMapper = mapperService.documentMapper(type);
for (Map.Entry<String, MetadataFieldMapper.TypeParser> entry : mapperService.mapperRegistry.getMetadataMapperParsers().entrySet()) {
final String name = entry.getKey();
final TypeParser parser = entry.getValue();
final MetadataFieldMapper metadataMapper = parser.getDefault(indexSettings, mapperService.fullName(name), builder.name());
final MetadataFieldMapper existingMetadataMapper = existingMapper == null
? null
: (MetadataFieldMapper) existingMapper.mappers().getMapper(name);
final MetadataFieldMapper metadataMapper;
if (existingMetadataMapper == null) {
final TypeParser parser = entry.getValue();
metadataMapper = parser.getDefault(indexSettings, mapperService.fullName(name), builder.name());
} else {
metadataMapper = existingMetadataMapper;
}
metadataMappers.put(metadataMapper.getClass(), metadataMapper);
}
}

View File

@ -34,6 +34,7 @@ import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.index.mapper.object.ObjectMapper;
import org.elasticsearch.test.ESSingleNodeTestCase;
import java.io.IOException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
@ -203,4 +204,28 @@ public class TestMergeMapperTests extends ESSingleNodeTestCase {
throw error.get();
}
}
public void testDoNotRepeatOriginalMapping() throws IOException {
CompressedXContent mapping = new CompressedXContent(XContentFactory.jsonBuilder().startObject()
.startObject("type")
.startObject("_source")
.field("enabled", false)
.endObject()
.endObject().endObject().bytes());
MapperService mapperService = createIndex("test").mapperService();
mapperService.merge("type", mapping, true, false);
CompressedXContent update = new CompressedXContent(XContentFactory.jsonBuilder().startObject()
.startObject("type")
.startObject("properties")
.startObject("foo")
.field("type", "string")
.endObject()
.endObject()
.endObject().endObject().bytes());
DocumentMapper mapper = mapperService.merge("type", update, false, false);
assertNotNull(mapper.mappers().getMapper("foo"));
assertFalse(mapper.sourceMapper().enabled());
}
}