@@ -196,7 +196,7 @@ public void testCreateAnomalyDetectorWithDuplicateName() throws Exception {
196
196
public void testCreateAnomalyDetectorWithFlattenedResultIndex () throws Exception {
197
197
AnomalyDetector detector = createIndexAndGetAnomalyDetector (
198
198
INDEX_NAME ,
199
- ImmutableList .of (TestHelpers .randomFeature (true )),
199
+ ImmutableList .of (TestHelpers .randomFeature ("feature_bytes" , "agg" , true )),
200
200
false ,
201
201
true
202
202
);
@@ -230,8 +230,21 @@ public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception
230
230
// ensure the flattened result index was created
231
231
String expectedFlattenedIndex = String
232
232
.format (Locale .ROOT , "opensearch-ad-plugin-result-test_flattened_%s" , id .toLowerCase (Locale .ROOT ));
233
- boolean indexExists = indexExists (expectedFlattenedIndex );
234
- assertTrue (indexExists );
233
+ boolean aliasExists = aliasExists (expectedFlattenedIndex );
234
+ assertTrue (aliasExists );
235
+ // ensure that the flattened field "feature_data_feature_bytes" exists in the mappings
236
+ String startDetectorEndpoint = String .format (Locale .ROOT , TestHelpers .AD_BASE_START_DETECTOR_URL , id );
237
+ Response startDetectorResponse = TestHelpers
238
+ .makeRequest (client (), "POST" , startDetectorEndpoint , ImmutableMap .of (), TestHelpers .toHttpEntity (detector ), null );
239
+ String getFlattenedResultIndexEndpoint = String
240
+ .format (Locale .ROOT , "/opensearch-ad-plugin-result-test_flattened_%s" , id .toLowerCase (Locale .ROOT ));
241
+ Response getIndexResponse = TestHelpers .makeRequest (client (), "GET" , getFlattenedResultIndexEndpoint , ImmutableMap .of (), "" , null );
242
+ Map <String , Object > flattenedResultIndex = entityAsMap (getIndexResponse );
243
+ Map <String , Object > mappings = (Map <String , Object >) flattenedResultIndex
244
+ .get ("opensearch-ad-plugin-result-test_flattened_" + id .toLowerCase (Locale .ROOT ));
245
+ Map <String , Object > properties = (Map <String , Object >) ((Map <String , Object >) mappings .get ("mappings" )).get ("properties" );
246
+ assertTrue ("Flattened field 'feature_data_feature_bytes' does not exist" , properties .containsKey ("feature_data_feature_bytes" ));
247
+
235
248
}
236
249
237
250
public void testCreateAnomalyDetector () throws Exception {
0 commit comments