diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index a2d222e33db39..4ba5e5a2b58e2 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -57,7 +57,9 @@ private DeprecationChecks() { IndexDeprecationChecks::percolatorUnmappedFieldsAsStringCheck, IndexDeprecationChecks::indexNameCheck, IndexDeprecationChecks::nodeLeftDelayedTimeCheck, - IndexDeprecationChecks::shardOnStartupCheck + IndexDeprecationChecks::shardOnStartupCheck, + IndexDeprecationChecks::classicSimilarityMappingCheck, + IndexDeprecationChecks::classicSimilaritySettingsCheck )); /** diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java index bfef54cf62394..b6397db8b9055 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java @@ -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 @@ -133,7 +134,38 @@ static DeprecationIssue percolatorUnmappedFieldsAsStringCheck(IndexMetaData inde } return null; } - + + static DeprecationIssue classicSimilarityMappingCheck(IndexMetaData indexMetaData) { + List 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 similarities = indexMetaData.getSettings().getGroups("index.similarity"); + List 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); @@ -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); diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java index 5935e50b3d1cc..82c1954816fe9 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java @@ -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; @@ -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 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 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);