@@ -95,67 +95,42 @@ public static void assertMlMappingsMatchTemplates(RestClient client) throws Exce
9595 }
9696
9797 /**
98- * Compares the mappings from the legacy template and the index and asserts
99- * they are the same. The assertion error message details the differences in
100- * the mappings.
101- *
102- * The Mappings, which are maps of maps, are flattened with the keys built
103- * from the keys of the sub-maps appended to the parent key.
104- * This makes diffing the 2 maps easier and diffs more comprehensible.
105- *
106- * The _meta field is not compared as it contains version numbers that
107- * change even when the mappings don't.
108- *
109- * Mistakes happen and some indices may be stuck with the incorrect mappings
110- * that cannot be fixed without re-index. In this case use the {@code exceptions}
111- * parameter to filter out fields in the index mapping that are not in the
112- * template. Each exception should be a '.' separated path to the value
113- * e.g. {@code properties.analysis.analysis_field.type}.
11498 *
115- * @param client The rest client to use
116- * @param templateName The template
117- * @param indexName The index
118- * @param notAnErrorIfIndexDoesNotExist The index may or may not have been created from
119- * the template. If {@code true} then the missing
120- * index does not cause an error
121- * @param exceptions List of keys to ignore in the index mappings.
122- * Each key is a '.' separated path.
123- * @param allowSystemIndexWarnings Whether deprecation warnings for system index access should be allowed/expected.
99+ * @param client The Rest client
100+ * @param templateName Template
101+ * @param version Expected template version
102+ * @param indexPatterns Expected index patterns
103+ * @throws Exception Assertion
124104 */
125105 @ SuppressWarnings ("unchecked" )
126- public static void assertLegacyTemplateMatchesIndexMappings (
127- RestClient client ,
128- String templateName ,
129- String indexName ,
130- boolean notAnErrorIfIndexDoesNotExist ,
131- Set <String > exceptions ,
132- boolean allowSystemIndexWarnings
133- ) throws Exception {
106+ public static void assertTemplateVersionAndPattern (RestClient client , String templateName , int version , List <String > indexPatterns )
107+ throws Exception {
134108
135109 AtomicReference <Response > templateResponse = new AtomicReference <>();
136110
137111 ESRestTestCase .assertBusy (() -> {
138- Request getTemplate = new Request ("GET" , "_template /" + templateName );
112+ Request getTemplate = new Request ("GET" , "_index_template /" + templateName );
139113 templateResponse .set (client .performRequest (getTemplate ));
140114 assertEquals ("missing template [" + templateName + "]" , 200 , templateResponse .get ().getStatusLine ().getStatusCode ());
141115 });
142116
143- Map <String , Object > templateMappings = (Map <String , Object >) XContentMapValues .extractValue (
144- ESRestTestCase .entityAsMap (templateResponse .get ()),
145- templateName ,
146- "mappings"
147- );
148- assertNotNull (templateMappings );
117+ var responseMap = ESRestTestCase .entityAsMap (templateResponse .get ());
118+ Integer templateVersion = ((List <Integer >) XContentMapValues .extractValue (
119+ responseMap ,
120+ "index_templates" ,
121+ "index_template" ,
122+ "version"
123+ )).getFirst ();
124+ assertEquals (version , templateVersion .intValue ());
149125
150- assertTemplateMatchesIndexMappingsCommon (
151- client ,
152- templateName ,
153- templateMappings ,
154- indexName ,
155- notAnErrorIfIndexDoesNotExist ,
156- exceptions ,
157- allowSystemIndexWarnings
158- );
126+ var templateIndexPatterns = ((List <String >) XContentMapValues .extractValue (
127+ responseMap ,
128+ "index_templates" ,
129+ "index_template" ,
130+ "index_patterns"
131+ ));
132+
133+ assertEquals (responseMap .toString (), templateIndexPatterns , indexPatterns );
159134 }
160135
161136 /**
0 commit comments