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 classic similarity #36577

Merged
merged 6 commits into from
Dec 18, 2018
Merged
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 @@ -54,7 +54,9 @@ private DeprecationChecks() {
IndexDeprecationChecks::percolatorUnmappedFieldsAsStringCheck,
IndexDeprecationChecks::indexNameCheck,
IndexDeprecationChecks::nodeLeftDelayedTimeCheck,
IndexDeprecationChecks::shardOnStartupCheck
IndexDeprecationChecks::shardOnStartupCheck,
IndexDeprecationChecks::classicSimilarityMappingCheck,
IndexDeprecationChecks::classicSimilaritySettingsCheck
));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* Index-specific deprecation checks
Expand Down Expand Up @@ -133,7 +134,38 @@ static DeprecationIssue percolatorUnmappedFieldsAsStringCheck(IndexMetaData inde
}
return null;
}


static DeprecationIssue classicSimilarityMappingCheck(IndexMetaData indexMetaData) {
List<String> issues = new ArrayList<>();
fieldLevelMappingIssue(indexMetaData, ((mappingMetaData, sourceAsMap) -> issues.addAll(
findInPropertiesRecursively(mappingMetaData.type(), sourceAsMap,
property -> "classic".equals(property.get("similarity"))))));
if (issues.size() > 0) {
return new DeprecationIssue(DeprecationIssue.Level.WARNING,
"Classic similarity has been removed",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"#_the_literal_classic_literal_similarity_has_been_removed",
"Fields which use classic similarity: " + issues.toString());
}
return null;
}

static DeprecationIssue classicSimilaritySettingsCheck(IndexMetaData indexMetaData) {
Map<String, Settings> similarities = indexMetaData.getSettings().getGroups("index.similarity");
List<String> classicSimilarities = similarities.entrySet().stream()
.filter(entry -> "classic".equals(entry.getValue().get("type")))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
if (classicSimilarities.size() > 0) {
return new DeprecationIssue(DeprecationIssue.Level.WARNING,
"Classic similarity has been removed",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"#_the_literal_classic_literal_similarity_has_been_removed",
"Custom similarities defined using classic similarity: " + classicSimilarities.toString());
}
return null;
}

static DeprecationIssue nodeLeftDelayedTimeCheck(IndexMetaData indexMetaData) {
String setting = UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey();
String value = indexMetaData.getSettings().get(setting);
Expand All @@ -150,7 +182,7 @@ static DeprecationIssue nodeLeftDelayedTimeCheck(IndexMetaData indexMetaData) {
}
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 @@ -15,6 +15,7 @@
import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -109,6 +110,53 @@ public void testPercolatorUnmappedFieldsAsStringCheck() {
assertTrue(noIssues.isEmpty());
}

public void testClassicSimilarityMappingCheck() throws IOException {
String mappingJson = "{\n" +
" \"properties\": {\n" +
" \"default_field\": {\n" +
" \"type\": \"text\"\n" +
" },\n" +
" \"classic_sim_field\": {\n" +
" \"type\": \"text\",\n" +
" \"similarity\": \"classic\"\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,
"Classic similarity has been removed",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"#_the_literal_classic_literal_similarity_has_been_removed",
"Fields which use classic similarity: [[type: _doc, field: classic_sim_field]]");
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(index));
assertEquals(singletonList(expected), issues);
}

public void testClassicSimilaritySettingsCheck() {
IndexMetaData index = IndexMetaData.builder(randomAlphaOfLengthBetween(5, 10))
.settings(settings(
VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.CURRENT)))
.put("index.similarity.my_classic_similarity.type", "classic")
.put("index.similarity.my_okay_similarity.type", "BM25"))
.numberOfShards(randomIntBetween(1, 100))
.numberOfReplicas(randomIntBetween(1, 100))
.build();

DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING,
"Classic similarity has been removed",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"#_the_literal_classic_literal_similarity_has_been_removed",
"Custom similarities defined using classic similarity: [my_classic_similarity]");
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(index));
assertEquals(singletonList(expected), issues);
}

public void testNodeLeftDelayedTimeCheck() {
String negativeTimeValue = "-" + randomPositiveTimeValue();
String indexName = randomAlphaOfLengthBetween(0, 10);
Expand Down