Search in sources :

Example 6 with SliceBuilder

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;
}
Also used : SearchRequest(org.opensearch.action.search.SearchRequest) SliceBuilder(org.opensearch.search.slice.SliceBuilder) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder)

Aggregations

SliceBuilder (org.opensearch.search.slice.SliceBuilder)6 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)2 Query (org.apache.lucene.search.Query)2 ParsedQuery (org.opensearch.index.query.ParsedQuery)2 SearchSourceBuilder (org.opensearch.search.builder.SearchSourceBuilder)2 IndexReader (org.apache.lucene.index.IndexReader)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 BoostQuery (org.apache.lucene.search.BoostQuery)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 QueryCachingPolicy (org.apache.lucene.search.QueryCachingPolicy)1 Sort (org.apache.lucene.search.Sort)1 Directory (org.apache.lucene.store.Directory)1 RandomIndexWriter (org.apache.lucene.tests.index.RandomIndexWriter)1 Mockito.anyString (org.mockito.Mockito.anyString)1 ActionRequestValidationException (org.opensearch.action.ActionRequestValidationException)1 SearchRequest (org.opensearch.action.search.SearchRequest)1 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)1 Settings (org.opensearch.common.settings.Settings)1