4141import org .elasticsearch .index .query .QueryBuilders ;
4242import org .elasticsearch .persistent .PersistentTasksCustomMetadata ;
4343import org .elasticsearch .plugins .Plugin ;
44- import org .elasticsearch .search .SearchService ;
4544import org .elasticsearch .search .builder .SearchSourceBuilder ;
4645import org .elasticsearch .tasks .RemovedTaskListener ;
4746import org .elasticsearch .tasks .Task ;
8281import static java .util .Collections .singleton ;
8382import static org .elasticsearch .action .admin .cluster .node .tasks .TestTaskPlugin .TEST_TASK_ACTION ;
8483import static org .elasticsearch .action .admin .cluster .node .tasks .TestTaskPlugin .UNBLOCK_TASK_ACTION ;
84+ import static org .elasticsearch .action .search .SearchQueryThenFetchAsyncAction .NODE_SEARCH_ACTION_NAME ;
85+ import static org .elasticsearch .action .search .SearchTransportService .FREE_CONTEXT_SCROLL_ACTION_NAME ;
8586import static org .elasticsearch .core .TimeValue .timeValueMillis ;
8687import static org .elasticsearch .core .TimeValue .timeValueSeconds ;
8788import static org .elasticsearch .http .HttpTransportSettings .SETTING_HTTP_MAX_HEADER_SIZE ;
@@ -353,8 +354,6 @@ public void testTransportBulkTasks() {
353354 }
354355
355356 public void testSearchTaskDescriptions () {
356- // TODO: enhance this test to also check the tasks created by batched query execution
357- updateClusterSettings (Settings .builder ().put (SearchService .BATCHED_QUERY_PHASE .getKey (), false ));
358357 registerTaskManagerListeners (TransportSearchAction .TYPE .name ()); // main task
359358 registerTaskManagerListeners (TransportSearchAction .TYPE .name () + "[*]" ); // shard task
360359 createIndex ("test" );
@@ -380,6 +379,11 @@ public void testSearchTaskDescriptions() {
380379 // check that if we have any shard-level requests they all have non-zero length description
381380 List <TaskInfo > shardTasks = findEvents (TransportSearchAction .TYPE .name () + "[*]" , Tuple ::v1 );
382381 for (TaskInfo taskInfo : shardTasks ) {
382+ // During batched query execution, if a partial reduction was done on the data node, a task will be created to free the reader.
383+ // These tasks don't have descriptions or parent tasks, so they're ignored for this test.
384+ if (taskInfo .action ().equals (FREE_CONTEXT_SCROLL_ACTION_NAME )) {
385+ continue ;
386+ }
383387 assertThat (taskInfo .parentTaskId (), notNullValue ());
384388 assertEquals (mainTask .get (0 ).taskId (), taskInfo .parentTaskId ());
385389 assertTaskHeaders (taskInfo );
@@ -396,12 +400,12 @@ public void testSearchTaskDescriptions() {
396400 taskInfo .description (),
397401 Regex .simpleMatch ("id[*], size[1], lastEmittedDoc[null]" , taskInfo .description ())
398402 );
403+ case NODE_SEARCH_ACTION_NAME -> assertEquals ("NodeQueryRequest" , taskInfo .description ());
399404 default -> fail ("Unexpected action [" + taskInfo .action () + "] with description [" + taskInfo .description () + "]" );
400405 }
401406 // assert that all task descriptions have non-zero length
402407 assertThat (taskInfo .description ().length (), greaterThan (0 ));
403408 }
404- updateClusterSettings (Settings .builder ().putNull (SearchService .BATCHED_QUERY_PHASE .getKey ()));
405409 }
406410
407411 public void testSearchTaskHeaderLimit () {
0 commit comments