-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add migration tool checks for _field_names disabling #46972
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
Changes from 5 commits
b3e5098
8c479cd
67e44ae
f00a419
6005486
d54c908
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,15 +12,19 @@ | |
| import org.elasticsearch.cluster.metadata.MappingMetaData; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.unit.TimeValue; | ||
| import org.elasticsearch.common.xcontent.XContentHelper; | ||
| import org.elasticsearch.index.IndexSettings; | ||
| import org.elasticsearch.index.mapper.FieldNamesFieldMapper; | ||
| import org.elasticsearch.ingest.IngestService; | ||
| import org.elasticsearch.ingest.PipelineConfiguration; | ||
| import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.stream.Collectors; | ||
|
|
||
|
|
@@ -91,6 +95,53 @@ static DeprecationIssue checkTemplatesWithTooManyFields(ClusterState state) { | |
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Check templates that use `_field_names` explicitly, which was deprecated in https://github.com/elastic/elasticsearch/pull/42854 | ||
| * and will throw an error on new indices in 8.0 | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| static DeprecationIssue checkTemplatesWithFieldNamesDisabled(ClusterState state) { | ||
| Set<String> templatesContainingFieldNames = new HashSet<>(); | ||
| state.getMetaData().getTemplates().forEach((templateCursor) -> { | ||
| String templateName = templateCursor.key; | ||
| templateCursor.value.getMappings().forEach((mappingCursor) -> { | ||
| String type = mappingCursor.key; | ||
| // there should be the type name at this level, but there was a bug where mappings could be stored without a type (#45120) | ||
| // to make sure, we try to detect this like we try to do in MappingMetaData#sourceAsMap() | ||
| Map<String, Object> mapping = XContentHelper.convertToMap(mappingCursor.value.compressedReference(), true).v2(); | ||
| if (mapping.size() == 1 && mapping.containsKey(type)) { | ||
| // the type name is the root value, reduce it | ||
| mapping = (Map<String, Object>) mapping.get(type); | ||
| } | ||
| if (mapContainsFieldNamesDisabled(mapping)) { | ||
| templatesContainingFieldNames.add(templateName); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| if (templatesContainingFieldNames.isEmpty() == false) { | ||
| return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, "Index templates contain _field_names settings.", | ||
| "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-8.0.html#fieldnames-enabling", | ||
| "Index templates " + templatesContainingFieldNames + " use the deprecated `enable` setting for the `" | ||
| + FieldNamesFieldMapper.NAME + "` field. Using this setting in new index mappings will throw an error " | ||
| + "in the next major version and needs to be removed from existing mappings and templates."); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * check for "_field_names" entries in the map that contain another property "enabled" in the sub-map | ||
| */ | ||
| static boolean mapContainsFieldNamesDisabled(Map<?, ?> map) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to use a recursive function here, or could we just check for it directly since we know
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opted for the recursive function just to make sure we catch all type-vs-no-type cases (see also the test cases). If we always have (or don't have) a type-level in the internally stored mappings in the templates, then we can probably do without but I wanted to check with you on this, it wasn't completely clear to me from reading the code. The mapping maps are quite forgiving for what you store in them, so it depends on the caller and I didn't completely follow the internal logic.
I saw and tried to use this, but ran into problems because it assumes things are stored under a Let me if you know for sure how the internal map structure is supposed to look like (at which level to expect the "_field_names" key) and I can update the tests accordingly and try making this non-recursive.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, I missed this -- then
I left some comments on your individual questions, let me know if anything is still unclear! |
||
| Object fieldNamesMapping = map.get(FieldNamesFieldMapper.NAME); | ||
| if (fieldNamesMapping != null) { | ||
| if (((Map<?, ?>) fieldNamesMapping).keySet().contains("enabled")) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| static DeprecationIssue checkPollIntervalTooLow(ClusterState state) { | ||
| String pollIntervalString = state.metaData().settings().get(LIFECYCLE_POLL_INTERVAL_SETTING.getKey()); | ||
| if (Strings.isNullOrEmpty(pollIntervalString)) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.