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 5d05bf4ef54..7c9037b1697 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 @@ -53,6 +53,7 @@ public class MlMappingsUpgradeIT extends AbstractUpgradeTestCase { break; case UPGRADED: assertUpgradedResultsMappings(); + assertUpgradedAnnotationsMappings(); closeAndReopenTestJob(); assertUpgradedConfigMappings(); assertMappingsMatchTemplates(); @@ -127,6 +128,37 @@ public class MlMappingsUpgradeIT extends AbstractUpgradeTestCase { }); } + @SuppressWarnings("unchecked") + private void assertUpgradedAnnotationsMappings() throws Exception { + + assertBusy(() -> { + Request getMappings = new Request("GET", ".ml-annotations-write/_mappings"); + Response response = client().performRequest(getMappings); + + Map responseLevel = entityAsMap(response); + assertNotNull(responseLevel); + Map indexLevel = null; + // The name of the concrete index underlying the annotations index write alias may or may not have been + // changed by the upgrade process (depending on what other tests are being run and the order they're run + // in), so navigating to the next level of the tree must account for both cases + for (Map.Entry entry : responseLevel.entrySet()) { + if (entry.getKey().startsWith(".ml-annotations-")) { + indexLevel = (Map) entry.getValue(); + break; + } + } + assertNotNull(indexLevel); + + assertEquals(Version.CURRENT.toString(), extractValue("mappings._meta.version", indexLevel)); + + // TODO: as the years go by, the field we assert on here should be changed + // to the most recent field we've added that would be incorrectly mapped by dynamic + // mappings, for example a field we want to be "keyword" incorrectly mapped as "text" + assertEquals("Incorrect type for event in " + responseLevel, "keyword", + extractValue("mappings.properties.event.type", indexLevel)); + }); + } + @SuppressWarnings("unchecked") private void assertUpgradedConfigMappings() throws Exception {