use of org.opensearch.search.slice.SliceBuilder in project OpenSearch by opensearch-project.
the class BulkByScrollParallelizationHelper method sliceIntoSubRequests.
/**
* Slice a search request into {@code times} separate search requests slicing on {@code field}. Note that the slices are *shallow*
* copies of this request so don't change them.
*/
static SearchRequest[] sliceIntoSubRequests(SearchRequest request, String field, int times) {
SearchRequest[] slices = new SearchRequest[times];
for (int slice = 0; slice < times; slice++) {
SliceBuilder sliceBuilder = new SliceBuilder(field, slice, times);
SearchSourceBuilder slicedSource;
if (request.source() == null) {
slicedSource = new SearchSourceBuilder().slice(sliceBuilder);
} else {
if (request.source().slice() != null) {
throw new IllegalStateException("Can't slice a request that already has a slice configuration");
}
slicedSource = request.source().shallowCopy().slice(sliceBuilder);
}
SearchRequest searchRequest = new SearchRequest(request);
searchRequest.source(slicedSource);
slices[slice] = searchRequest;
}
return slices;
}
Aggregations