diff --git a/docs/changelog/138097.yaml b/docs/changelog/138097.yaml new file mode 100644 index 0000000000000..fc3e2f58b7004 --- /dev/null +++ b/docs/changelog/138097.yaml @@ -0,0 +1,5 @@ +pr: 138097 +summary: Bump anomalies index template version to install latest +area: Machine Learning +type: bug +issues: [] diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlIndexTemplateRegistry.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlIndexTemplateRegistry.java index 57a1dcb9bd0b0..80c4a7a015a5c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlIndexTemplateRegistry.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlIndexTemplateRegistry.java @@ -40,9 +40,10 @@ public class MlIndexTemplateRegistry extends IndexTemplateRegistry { * the state index has no mappings - its template basically just says * this - hence there's no mappings version for the state index. Please * add a comment with a reason each time the base number is incremented. - * 10000001: TODO - reason + * + * 10000001: ".reindexed-v7-ml-anomalies-*" added to ml-anomalies index pattern */ - public static final int ML_INDEX_TEMPLATE_VERSION = 10000000 + AnomalyDetectorsIndex.RESULTS_INDEX_MAPPINGS_VERSION + public static final int ML_INDEX_TEMPLATE_VERSION = 10000001 + AnomalyDetectorsIndex.RESULTS_INDEX_MAPPINGS_VERSION + NotificationsIndex.NOTIFICATIONS_INDEX_MAPPINGS_VERSION + MlStatsIndex.STATS_INDEX_MAPPINGS_VERSION + NotificationsIndex.NOTIFICATIONS_INDEX_TEMPLATE_VERSION; diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlMappingsUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlMappingsUpgradeIT.java index cde88089d4330..ec0714c17919d 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlMappingsUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlMappingsUpgradeIT.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -71,6 +72,14 @@ public void testMappingsUpgrade() throws Exception { assertMlLegacyTemplatesDeleted(); IndexMappingTemplateAsserter.assertMlMappingsMatchTemplates(client()); assertNotificationsIndexAliasCreated(); + assertBusy( + () -> IndexMappingTemplateAsserter.assertTemplateVersionAndPattern( + client(), + ".ml-anomalies-", + 10000005, + List.of(".ml-anomalies-*", ".reindexed-v7-ml-anomalies-*") + ) + ); break; default: throw new UnsupportedOperationException("Unknown cluster type [" + CLUSTER_TYPE + "]"); diff --git a/x-pack/qa/src/main/java/org/elasticsearch/xpack/test/rest/IndexMappingTemplateAsserter.java b/x-pack/qa/src/main/java/org/elasticsearch/xpack/test/rest/IndexMappingTemplateAsserter.java index 6d8a50c14cf95..154d01d596cf0 100644 --- a/x-pack/qa/src/main/java/org/elasticsearch/xpack/test/rest/IndexMappingTemplateAsserter.java +++ b/x-pack/qa/src/main/java/org/elasticsearch/xpack/test/rest/IndexMappingTemplateAsserter.java @@ -95,67 +95,42 @@ public static void assertMlMappingsMatchTemplates(RestClient client) throws Exce } /** - * Compares the mappings from the legacy template and the index and asserts - * they are the same. The assertion error message details the differences in - * the mappings. - * - * The Mappings, which are maps of maps, are flattened with the keys built - * from the keys of the sub-maps appended to the parent key. - * This makes diffing the 2 maps easier and diffs more comprehensible. - * - * The _meta field is not compared as it contains version numbers that - * change even when the mappings don't. - * - * Mistakes happen and some indices may be stuck with the incorrect mappings - * that cannot be fixed without re-index. In this case use the {@code exceptions} - * parameter to filter out fields in the index mapping that are not in the - * template. Each exception should be a '.' separated path to the value - * e.g. {@code properties.analysis.analysis_field.type}. * - * @param client The rest client to use - * @param templateName The template - * @param indexName The index - * @param notAnErrorIfIndexDoesNotExist The index may or may not have been created from - * the template. If {@code true} then the missing - * index does not cause an error - * @param exceptions List of keys to ignore in the index mappings. - * Each key is a '.' separated path. - * @param allowSystemIndexWarnings Whether deprecation warnings for system index access should be allowed/expected. + * @param client The Rest client + * @param templateName Template + * @param version Expected template version + * @param indexPatterns Expected index patterns + * @throws Exception Assertion */ @SuppressWarnings("unchecked") - public static void assertLegacyTemplateMatchesIndexMappings( - RestClient client, - String templateName, - String indexName, - boolean notAnErrorIfIndexDoesNotExist, - Set exceptions, - boolean allowSystemIndexWarnings - ) throws Exception { + public static void assertTemplateVersionAndPattern(RestClient client, String templateName, int version, List indexPatterns) + throws Exception { AtomicReference templateResponse = new AtomicReference<>(); ESRestTestCase.assertBusy(() -> { - Request getTemplate = new Request("GET", "_template/" + templateName); + Request getTemplate = new Request("GET", "_index_template/" + templateName); templateResponse.set(client.performRequest(getTemplate)); assertEquals("missing template [" + templateName + "]", 200, templateResponse.get().getStatusLine().getStatusCode()); }); - Map templateMappings = (Map) XContentMapValues.extractValue( - ESRestTestCase.entityAsMap(templateResponse.get()), - templateName, - "mappings" - ); - assertNotNull(templateMappings); + var responseMap = ESRestTestCase.entityAsMap(templateResponse.get()); + Integer templateVersion = ((List) XContentMapValues.extractValue( + responseMap, + "index_templates", + "index_template", + "version" + )).getFirst(); + assertEquals(version, templateVersion.intValue()); - assertTemplateMatchesIndexMappingsCommon( - client, - templateName, - templateMappings, - indexName, - notAnErrorIfIndexDoesNotExist, - exceptions, - allowSystemIndexWarnings - ); + var templateIndexPatterns = ((List) XContentMapValues.extractValue( + responseMap, + "index_templates", + "index_template", + "index_patterns" + )); + + assertEquals(responseMap.toString(), templateIndexPatterns, indexPatterns); } /**