Skip to content
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

Deprecation check for index_options on numeric fields #37026

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private DeprecationChecks() {
IndexDeprecationChecks::percolatorUnmappedFieldsAsStringCheck,
IndexDeprecationChecks::indexNameCheck,
IndexDeprecationChecks::nodeLeftDelayedTimeCheck,
IndexDeprecationChecks::indexOptionsOnNumericFieldsCheck,
IndexDeprecationChecks::shardOnStartupCheck,
IndexDeprecationChecks::classicSimilarityMappingCheck,
IndexDeprecationChecks::classicSimilaritySettingsCheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


import com.carrotsearch.hppc.cursors.ObjectCursor;

import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData;
Expand All @@ -20,8 +19,12 @@
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -184,6 +187,24 @@ static DeprecationIssue nodeLeftDelayedTimeCheck(IndexMetaData indexMetaData) {
return null;
}

static DeprecationIssue indexOptionsOnNumericFieldsCheck(IndexMetaData indexMetaData) {
final Set<String> numericTypes = Collections.unmodifiableSet(new HashSet<>(
Arrays.asList("byte", "short", "integer", "long", "float", "double", "half_float")));

List<String> issues = new ArrayList<>();
fieldLevelMappingIssue(indexMetaData, ((mappingMetaData, sourceAsMap) -> issues.addAll(
findInPropertiesRecursively(mappingMetaData.type(), sourceAsMap,
property -> numericTypes.contains(property.get("type")) && property.containsKey("index_options")))));
if (issues.size() > 0) {
return new DeprecationIssue(DeprecationIssue.Level.WARNING,
"index_options is no longer supported on numeric fields",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
"#_literal_index_options_literal_for_numeric_fields_has_been_removed",
"Numeric fields which have index_options set: " + issues.toString());
}
return null;
}

static DeprecationIssue shardOnStartupCheck(IndexMetaData indexMetaData) {
String setting = IndexSettings.INDEX_CHECK_ON_STARTUP.getKey();
String value = indexMetaData.getSettings().get(setting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,36 @@ public void testNodeLeftDelayedTimeCheck() {
assertTrue(noIssues.isEmpty());
}

public void testIndexOptionsOnNumericFieldsCheck() throws IOException {
String[] possibleIndexOptions = {"docs", "freqs", "positions", "offsets"};
String mappingJson = "{\n" +
" \"properties\": {\n" +
" \"text_field\": {\n" +
" \"type\": \"text\",\n" +
" \"index_options\": \"" + randomFrom(possibleIndexOptions) + "\"\n" +
" },\n" +
" \"numeric_field\": {\n" +
" \"type\": \"" + randomFrom("byte", "short", "integer", "long", "float", "double", "half_float") + "\",\n" +
" \"index_options\": \"" + randomFrom(possibleIndexOptions) + "\"\n" +
" }\n" +
" }\n" +
"}";
IndexMetaData index = IndexMetaData.builder(randomAlphaOfLengthBetween(5,10))
.settings(settings(
VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.CURRENT))))
.numberOfShards(randomIntBetween(1,100))
.numberOfReplicas(randomIntBetween(1, 100))
.putMapping("_doc", mappingJson)
.build();
DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING,
"index_options is no longer supported on numeric fields",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
"#_literal_index_options_literal_for_numeric_fields_has_been_removed",
"Numeric fields which have index_options set: [[type: _doc, field: numeric_field]]");
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(index));
assertEquals(singletonList(expected), issues);
}

public void testShardOnStartupCheck() {
String indexName = randomAlphaOfLengthBetween(0, 10);
String setting = IndexSettings.INDEX_CHECK_ON_STARTUP.getKey();
Expand Down