-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mappings: Same code path for dynamic mappings updates and updates com…
…ing from the API. We have two completely different code paths for mappings updates, depending on whether they come from the API or are guessed based on the parsed documents. This commit makes dynamic mappings updates execute like updates from the API. The only change in behaviour is that a document that fails parsing can not modify mappings anymore (useful to prevent issues such as #9851). Other than that, this change should be fairly transparent to users but working this way opens doors to other changes such as validating dynamic mappings updates on the master node (#8688). The way it works internally is that Mapper.parse now returns a Mapper instead of being void. The returned Mapper represents a mapping update that has been performed in order to parse the document. Mappings updates are propagated recursively back to the root mapper, and once parsing is finished, we check that the mappings update can be applied, and either fail the parsing if the update cannot be merged (eg. because of a concurrent mapping update from the API) or merge the update into the mappings. However not all mappings updates can be applied recursively, `copy_to` for instance can add mappings at totally different places in the tree. Because of it I added ParseContext.rootMapperUpdates which `copy_to` fills when the field to copy data to does not exist in the mappings yet. These mappings updates are merged from the ones generated by regular parsing. One particular mapping update was the `auto_boost` setting on the `all` root mapper. Being tricky to work on, I removed it in favour of search-time checks that payloads have been indexed. One interesting side-effect of the change is that concurrency on ObjectMapper is greatly simplified since we do not have to care anymore about having concurrent dynamic mappings and API updates.
- Loading branch information
Showing
38 changed files
with
806 additions
and
534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/java/org/elasticsearch/index/mapper/MapperUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.index.mapper; | ||
|
||
import org.elasticsearch.ElasticsearchIllegalStateException; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.index.mapper.object.ObjectMapper; | ||
import org.elasticsearch.index.mapper.object.RootObjectMapper; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public enum MapperUtils { | ||
; | ||
|
||
/** | ||
* Parse the given {@code context} with the given {@code mapper} and apply | ||
* the potential mapping update in-place. This method is useful when | ||
* composing mapping updates. | ||
*/ | ||
public static <M extends Mapper> M parseAndMergeUpdate(M mapper, ParseContext context) throws IOException { | ||
final Mapper update = mapper.parse(context); | ||
if (update != null) { | ||
merge(mapper, update); | ||
} | ||
return mapper; | ||
} | ||
|
||
/** | ||
* Merge {@code mergeWith} into {@code mergeTo}. Note: this method only | ||
* merges mappings, not lookup structures. Conflicts are returned as exceptions. | ||
*/ | ||
public static void merge(Mapper mergeInto, Mapper mergeWith) { | ||
MergeContext ctx = new MergeContext(new DocumentMapper.MergeFlags().simulate(false)) { | ||
|
||
@Override | ||
public boolean hasConflicts() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String[] buildConflicts() { | ||
return Strings.EMPTY_ARRAY; | ||
} | ||
|
||
@Override | ||
public void addObjectMappers(Collection<ObjectMapper> objectMappers) { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public void addFieldMappers(List<FieldMapper<?>> fieldMappers) { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public void addConflict(String mergeFailure) { | ||
throw new ElasticsearchIllegalStateException("Merging dynamic updates triggered a conflict: " + mergeFailure); | ||
} | ||
}; | ||
mergeInto.merge(mergeWith, ctx); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.