@@ -2973,9 +2973,13 @@ private static void expectSearch(Response response, String... docIds) throws IOE
29732973 final SearchResponse searchResponse = SearchResponseUtils .parseSearchResponse (responseAsParser (response ));
29742974 try {
29752975 SearchHit [] hits = searchResponse .getHits ().getHits ();
2976- assertThat (hits .length , equalTo (docIds .length ));
2977- List <String > actualDocIds = Arrays .stream (hits ).map (SearchHit ::getId ).toList ();
2978- assertThat (actualDocIds , containsInAnyOrder (docIds ));
2976+ if (docIds != null ) {
2977+ assertThat (Arrays .toString (hits ), hits .length , equalTo (docIds .length ));
2978+ List <String > actualDocIds = Arrays .stream (hits ).map (SearchHit ::getId ).toList ();
2979+ assertThat (actualDocIds , containsInAnyOrder (docIds ));
2980+ } else {
2981+ assertThat (hits .length , equalTo (0 ));
2982+ }
29792983 } finally {
29802984 searchResponse .decRef ();
29812985 }
@@ -3019,6 +3023,32 @@ private List<String> setupDataStream() throws IOException {
30193023 return randomBoolean () ? populateDataStreamWithBulkRequest () : populateDataStreamWithDocRequests ();
30203024 }
30213025
3026+ @ SuppressWarnings ("unchecked" )
3027+ private List <String > setupOtherDataStream () throws IOException {
3028+ createOtherTemplates ();
3029+
3030+ var bulkRequest = new Request ("POST" , "/_bulk?refresh=true" );
3031+ bulkRequest .setJsonEntity ("""
3032+ { "create" : { "_index" : "other1", "_id" : "3" } }
3033+ { "@timestamp": 3, "age" : 1, "name" : "jane", "email" : "[email protected] " } 3034+ { "create" : { "_index" : "other1", "_id" : "4" } }
3035+ { "@timestamp": 4, "age" : "this should be an int", "name" : "jane", "email" : "[email protected] " } 3036+ """ );
3037+ Response response = performRequest (WRITE_ACCESS , bulkRequest );
3038+ assertOK (response );
3039+ // we need this dance because the ID for the failed document is random, **not** 4
3040+ Map <String , Object > stringObjectMap = responseAsMap (response );
3041+ List <Object > items = (List <Object >) stringObjectMap .get ("items" );
3042+ List <String > ids = new ArrayList <>();
3043+ for (Object item : items ) {
3044+ Map <String , Object > itemMap = (Map <String , Object >) item ;
3045+ Map <String , Object > create = (Map <String , Object >) itemMap .get ("create" );
3046+ assertThat (create .get ("status" ), equalTo (201 ));
3047+ ids .add ((String ) create .get ("_id" ));
3048+ }
3049+ return ids ;
3050+ }
3051+
30223052 private void createTemplates () throws IOException {
30233053 var componentTemplateRequest = new Request ("PUT" , "/_component_template/component1" );
30243054 componentTemplateRequest .setJsonEntity ("""
@@ -3062,6 +3092,49 @@ private void createTemplates() throws IOException {
30623092 assertOK (adminClient ().performRequest (indexTemplateRequest ));
30633093 }
30643094
3095+ private void createOtherTemplates () throws IOException {
3096+ var componentTemplateRequest = new Request ("PUT" , "/_component_template/component2" );
3097+ componentTemplateRequest .setJsonEntity ("""
3098+ {
3099+ "template": {
3100+ "mappings": {
3101+ "properties": {
3102+ "@timestamp": {
3103+ "type": "date"
3104+ },
3105+ "age": {
3106+ "type": "integer"
3107+ },
3108+ "email": {
3109+ "type": "keyword"
3110+ },
3111+ "name": {
3112+ "type": "text"
3113+ }
3114+ }
3115+ },
3116+ "data_stream_options": {
3117+ "failure_store": {
3118+ "enabled": true
3119+ }
3120+ }
3121+ }
3122+ }
3123+ """ );
3124+ assertOK (adminClient ().performRequest (componentTemplateRequest ));
3125+
3126+ var indexTemplateRequest = new Request ("PUT" , "/_index_template/template2" );
3127+ indexTemplateRequest .setJsonEntity ("""
3128+ {
3129+ "index_patterns": ["other*"],
3130+ "data_stream": {},
3131+ "priority": 500,
3132+ "composed_of": ["component1"]
3133+ }
3134+ """ );
3135+ assertOK (adminClient ().performRequest (indexTemplateRequest ));
3136+ }
3137+
30653138 private List <String > populateDataStreamWithDocRequests () throws IOException {
30663139 List <String > ids = new ArrayList <>();
30673140
@@ -3181,6 +3254,11 @@ protected String createAndStoreApiKey(String username, @Nullable String roleDesc
31813254 return apiKeys .get (username );
31823255 }
31833256
3257+ protected String createOrUpdateApiKey (String username , @ Nullable String roleDescriptors ) throws IOException {
3258+ apiKeys .put (username , createApiKey (username , roleDescriptors ));
3259+ return apiKeys .get (username );
3260+ }
3261+
31843262 private String createApiKey (String username , String roleDescriptors ) throws IOException {
31853263 var request = new Request ("POST" , "/_security/api_key" );
31863264 if (roleDescriptors == null ) {
0 commit comments