Skip to content

Commit

Permalink
Allow unsetting index.mapper.dynamic
Browse files Browse the repository at this point in the history
When migrating from older versions of OpenSearch index.mapper.dynamic
can be set to false/null and safely ignored.  This allows updating
settings for indices with a value of true being unset or false so the
index can be migrated.

Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Nov 14, 2023
1 parent 6c980bc commit d444735
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix passing wrong parameter when calling newConfigurationException() in DotExpanderProcessor ([#10737](https://github.com/opensearch-project/OpenSearch/pull/10737))
- Fix SuggestSearch.testSkipDuplicates by forceing refresh when indexing its test documents ([#11068](https://github.com/opensearch-project/OpenSearch/pull/11068))
- Adding version condition while adding geoshape doc values to the index, to ensure backward compatibility.([#11095](https://github.com/opensearch-project/OpenSearch/pull/11095))
- Allow unsetting of index.mapper.dynamic ([](https://github.com/opensearch-project/OpenSearch/pull/))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public enum MergeReason {
Property.Dynamic,
Property.IndexScope
);
public static final boolean INDEX_MAPPER_DYNAMIC_DEFAULT = true;
public static final boolean INDEX_MAPPER_DYNAMIC_DEFAULT = false;
@Deprecated
public static final Setting<Boolean> INDEX_MAPPER_DYNAMIC_SETTING = Setting.boolSetting(
"index.mapper.dynamic",
Expand Down Expand Up @@ -224,7 +224,7 @@ public MapperService(
this.mapperRegistry = mapperRegistry;
this.idFieldDataEnabled = idFieldDataEnabled;

if (INDEX_MAPPER_DYNAMIC_SETTING.exists(indexSettings.getSettings())) {
if (INDEX_MAPPER_DYNAMIC_SETTING.get(indexSettings.getSettings()) != INDEX_MAPPER_DYNAMIC_DEFAULT) {
throw new IllegalArgumentException("Setting " + INDEX_MAPPER_DYNAMIC_SETTING.getKey() + " was removed after version 6.0.0");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import java.util.Map;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
Expand Down Expand Up @@ -499,6 +500,39 @@ public void testReloadSearchAnalyzers() throws IOException {
);
}

public void testMapperDynamicNotAllowed() {
final Settings settingsAsTrue = Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)
.put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), "true")
.build();

final IllegalArgumentException iaeWhenTrue = assertThrows(IllegalArgumentException.class, () -> createIndex("test1", settingsAsTrue).mapperService());
assertThat(iaeWhenTrue.getMessage(), equalTo("Setting index.mapper.dynamic was removed after version 6.0.0"));

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.");
}

public void testMapperDynamicAllowedWhenNullOrFalse() {
final Settings settingsAsNull = Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)
.putNull(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey())
.build();

createIndex("test1", settingsAsNull).mapperService();

final Settings settingsAsFalse = Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)
.put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), "false")
.build();

createIndex("test2", settingsAsFalse).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 d444735

Please sign in to comment.