Skip to content

Commit

Permalink
Warn about index.mapper.dynamic usage instead of erroring (opensear…
Browse files Browse the repository at this point in the history
…ch-project#11193)

When migrating from older versions of OpenSearch index.mapper.dynamic
could be present, use the deprecation system to warn about this state and
ignore this legacy setting so the index is usable.

Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Feb 21, 2024
1 parent e97bee8 commit f34ca96
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add a system property to configure YamlParser codepoint limits ([#12298](https://github.com/opensearch-project/OpenSearch/pull/12298))
- Prevent read beyond slice boundary in ByteArrayIndexInput ([#10481](https://github.com/opensearch-project/OpenSearch/issues/10481))
- Fix the "highlight.max_analyzer_offset" request parameter with "plain" highlighter ([#10919](https://github.com/opensearch-project/OpenSearch/pull/10919))
- Warn about deprecated and ignored index.mapper.dynamic index setting ([#11193](https://github.com/opensearch-project/OpenSearch/pull/11193))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public MapperService(
ScriptService scriptService
) {
super(indexSettings);

this.indexVersionCreated = indexSettings.getIndexVersionCreated();
this.indexAnalyzers = indexAnalyzers;
this.documentParser = new DocumentMapperParser(
Expand All @@ -261,7 +262,12 @@ public MapperService(
this.idFieldDataEnabled = idFieldDataEnabled;

if (INDEX_MAPPER_DYNAMIC_SETTING.exists(indexSettings.getSettings())) {
throw new IllegalArgumentException("Setting " + INDEX_MAPPER_DYNAMIC_SETTING.getKey() + " was removed after version 6.0.0");
deprecationLogger.deprecate(
index().getName() + INDEX_MAPPER_DYNAMIC_SETTING.getKey(),
"Index [{}] has setting [{}] that is not supported in OpenSearch, its value will be ignored.",
index().getName(),
INDEX_MAPPER_DYNAMIC_SETTING.getKey()
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -541,6 +543,28 @@ public void testReloadSearchAnalyzers() throws IOException {
);
}

public void testMapperDynamicAllowedIgnored() {
final List<Function<Settings.Builder, Settings.Builder>> scenarios = List.of(
(builder) -> builder.putNull(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey()),
(builder) -> builder.put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), true),
(builder) -> builder.put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), false)
);

for (int i = 0; i < scenarios.size(); i++) {
final Settings.Builder defaultSettingsBuilder = Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1);

final Settings settings = scenarios.get(i).apply(defaultSettingsBuilder).build();

createIndex("test" + i, settings).mapperService();
}

assertWarnings(
"[index.mapper.dynamic] setting was deprecated in OpenSearch and will be removed in a future release! See the breaking changes documentation for the next major version."
);
}

private boolean assertSameContainedFilters(TokenFilterFactory[] originalTokenFilter, NamedAnalyzer updatedAnalyzer) {
ReloadableCustomAnalyzer updatedReloadableAnalyzer = (ReloadableCustomAnalyzer) updatedAnalyzer.analyzer();
TokenFilterFactory[] newTokenFilters = updatedReloadableAnalyzer.getComponents().getTokenFilters();
Expand Down

0 comments on commit f34ca96

Please sign in to comment.