Merge pull request #16023 from jpountz/fix/implicit_self_conflict
Reuse metadata mappers for dynamic updates.
This commit is contained in:
commit
a90d2fa0b4
|
@ -79,10 +79,20 @@ public class DocumentMapper implements ToXContent {
|
||||||
this.builderContext = new Mapper.BuilderContext(indexSettings, new ContentPath(1));
|
this.builderContext = new Mapper.BuilderContext(indexSettings, new ContentPath(1));
|
||||||
this.rootObjectMapper = builder.build(builderContext);
|
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()) {
|
for (Map.Entry<String, MetadataFieldMapper.TypeParser> entry : mapperService.mapperRegistry.getMetadataMapperParsers().entrySet()) {
|
||||||
final String name = entry.getKey();
|
final String name = entry.getKey();
|
||||||
final TypeParser parser = entry.getValue();
|
final MetadataFieldMapper existingMetadataMapper = existingMapper == null
|
||||||
final MetadataFieldMapper metadataMapper = parser.getDefault(indexSettings, mapperService.fullName(name), builder.name());
|
? 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);
|
metadataMappers.put(metadataMapper.getClass(), metadataMapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.elasticsearch.index.mapper.core.StringFieldMapper;
|
||||||
import org.elasticsearch.index.mapper.object.ObjectMapper;
|
import org.elasticsearch.index.mapper.object.ObjectMapper;
|
||||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.concurrent.CyclicBarrier;
|
import java.util.concurrent.CyclicBarrier;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
@ -203,4 +204,28 @@ public class TestMergeMapperTests extends ESSingleNodeTestCase {
|
||||||
throw error.get();
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue