public AbstractAsyncBulkByScrollAction(BulkByScrollTask task, Logger logger, ParentTaskAssigningClient client, ThreadPool threadPool, Request mainRequest, ScriptService scriptService, ClusterState clusterState, ActionListener<BulkByScrollResponse> listener) { this.task = task; if (!task.isWorker()) { throw new IllegalArgumentException("Given task [" + task.getId() + "] must have a child worker"); } this.worker = task.getWorkerState(); this.logger = logger; this.client = client; this.threadPool = threadPool; this.scriptService = scriptService; this.clusterState = clusterState; this.mainRequest = mainRequest; this.listener = listener; BackoffPolicy backoffPolicy = buildBackoffPolicy(); bulkRetry = new Retry(BackoffPolicy.wrap(backoffPolicy, worker::countBulkRetry), threadPool); scrollSource = buildScrollableResultSource(backoffPolicy); scriptApplier = Objects.requireNonNull(buildScriptApplier(), "script applier must not be null"); /* * Default to sorting by doc. We can't do this in the request itself because it is normal to *add* to the sorts rather than replace * them and if we add _doc as the first sort by default then sorts will never work.... So we add it here, only if there isn't * another sort. */ List<SortBuilder<?>> sorts = mainRequest.getSearchRequest().source().sorts(); if (sorts == null || sorts.isEmpty()) { mainRequest.getSearchRequest().source().sort(fieldSort("_doc")); } mainRequest.getSearchRequest().source().version(needsSourceDocumentVersions()); }