Preserve existing mappings on batch mapping updates
This commit addresses an issues introduced in #14899 to apply mapping updates in batches. The issue is that an existing mapping for a type could be lost if that type came in a batch that already contained a mapping update for another type on the same index. The underlying issue was that the existing mapping would not be merged in because the merging logic was only tripped once per index, rather than for all types seeing updates for each index. Resolving this issue is simply a matter of ensuring that all existing types seeing updates are merged in. Closes #15129
This commit is contained in:
parent
fb79d064d7
commit
eea72a6d86
|
@ -221,9 +221,8 @@ public class MetaDataMappingService extends AbstractComponent {
|
||||||
class PutMappingExecutor implements ClusterStateTaskExecutor<PutMappingClusterStateUpdateRequest> {
|
class PutMappingExecutor implements ClusterStateTaskExecutor<PutMappingClusterStateUpdateRequest> {
|
||||||
@Override
|
@Override
|
||||||
public BatchResult<PutMappingClusterStateUpdateRequest> execute(ClusterState currentState, List<PutMappingClusterStateUpdateRequest> tasks) throws Exception {
|
public BatchResult<PutMappingClusterStateUpdateRequest> execute(ClusterState currentState, List<PutMappingClusterStateUpdateRequest> tasks) throws Exception {
|
||||||
List<String> indicesToClose = new ArrayList<>();
|
Set<String> indicesToClose = new HashSet<>();
|
||||||
BatchResult.Builder<PutMappingClusterStateUpdateRequest> builder = BatchResult.builder();
|
BatchResult.Builder<PutMappingClusterStateUpdateRequest> builder = BatchResult.builder();
|
||||||
Map<PutMappingClusterStateUpdateRequest, TaskResult> executionResults = new HashMap<>();
|
|
||||||
try {
|
try {
|
||||||
// precreate incoming indices;
|
// precreate incoming indices;
|
||||||
for (PutMappingClusterStateUpdateRequest request : tasks) {
|
for (PutMappingClusterStateUpdateRequest request : tasks) {
|
||||||
|
@ -231,10 +230,15 @@ public class MetaDataMappingService extends AbstractComponent {
|
||||||
for (String index : request.indices()) {
|
for (String index : request.indices()) {
|
||||||
if (currentState.metaData().hasIndex(index)) {
|
if (currentState.metaData().hasIndex(index)) {
|
||||||
// if we don't have the index, we will throw exceptions later;
|
// if we don't have the index, we will throw exceptions later;
|
||||||
if (indicesService.hasIndex(index) == false) {
|
if (indicesService.hasIndex(index) == false || indicesToClose.contains(index)) {
|
||||||
final IndexMetaData indexMetaData = currentState.metaData().index(index);
|
final IndexMetaData indexMetaData = currentState.metaData().index(index);
|
||||||
IndexService indexService = indicesService.createIndex(nodeServicesProvider, indexMetaData, Collections.EMPTY_LIST);
|
IndexService indexService;
|
||||||
indicesToClose.add(indexMetaData.getIndex());
|
if (indicesService.hasIndex(index) == false) {
|
||||||
|
indexService = indicesService.createIndex(nodeServicesProvider, indexMetaData, Collections.EMPTY_LIST);
|
||||||
|
indicesToClose.add(index);
|
||||||
|
} else {
|
||||||
|
indexService = indicesService.indexService(index);
|
||||||
|
}
|
||||||
// make sure to add custom default mapping if exists
|
// make sure to add custom default mapping if exists
|
||||||
if (indexMetaData.getMappings().containsKey(MapperService.DEFAULT_MAPPING)) {
|
if (indexMetaData.getMappings().containsKey(MapperService.DEFAULT_MAPPING)) {
|
||||||
indexService.mapperService().merge(MapperService.DEFAULT_MAPPING, indexMetaData.getMappings().get(MapperService.DEFAULT_MAPPING).source(), false, request.updateAllTypes());
|
indexService.mapperService().merge(MapperService.DEFAULT_MAPPING, indexMetaData.getMappings().get(MapperService.DEFAULT_MAPPING).source(), false, request.updateAllTypes());
|
||||||
|
|
|
@ -51,7 +51,6 @@ import static org.hamcrest.Matchers.*;
|
||||||
@ClusterScope(randomDynamicTemplates = false)
|
@ClusterScope(randomDynamicTemplates = false)
|
||||||
public class UpdateMappingIntegrationIT extends ESIntegTestCase {
|
public class UpdateMappingIntegrationIT extends ESIntegTestCase {
|
||||||
|
|
||||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/15129")
|
|
||||||
public void testDynamicUpdates() throws Exception {
|
public void testDynamicUpdates() throws Exception {
|
||||||
client().admin().indices().prepareCreate("test")
|
client().admin().indices().prepareCreate("test")
|
||||||
.setSettings(
|
.setSettings(
|
||||||
|
|
Loading…
Reference in New Issue