Search in sources :

Example 96 with SearchRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.

the class AbstractBulkByScrollRequest method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    searchRequest = new SearchRequest();
    searchRequest.readFrom(in);
    abortOnVersionConflict = in.readBoolean();
    size = in.readVInt();
    refresh = in.readBoolean();
    timeout = new TimeValue(in);
    activeShardCount = ActiveShardCount.readFrom(in);
    retryBackoffInitialTime = new TimeValue(in);
    maxRetries = in.readVInt();
    requestsPerSecond = in.readFloat();
    if (in.getVersion().onOrAfter(Version.V_5_1_1_UNRELEASED)) {
        slices = in.readVInt();
    } else {
        slices = 1;
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 97 with SearchRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.

the class BulkByScrollParallelizationHelper method startSlices.

public static <Request extends AbstractBulkByScrollRequest<Request>> void startSlices(Client client, TaskManager taskManager, Action<Request, BulkByScrollResponse, ?> action, String localNodeId, ParentBulkByScrollTask task, Request request, ActionListener<BulkByScrollResponse> listener) {
    TaskId parentTaskId = new TaskId(localNodeId, task.getId());
    for (final SearchRequest slice : sliceIntoSubRequests(request.getSearchRequest(), UidFieldMapper.NAME, request.getSlices())) {
        // TODO move the request to the correct node. maybe here or somehow do it as part of startup for reindex in general....
        Request requestForSlice = request.forSlice(parentTaskId, slice);
        ActionListener<BulkByScrollResponse> sliceListener = ActionListener.wrap(r -> task.onSliceResponse(listener, slice.source().slice().getId(), r), e -> task.onSliceFailure(listener, slice.source().slice().getId(), e));
        client.execute(action, requestForSlice, sliceListener);
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) TaskId(org.elasticsearch.tasks.TaskId) SearchRequest(org.elasticsearch.action.search.SearchRequest)

Example 98 with SearchRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.

the class AsyncBulkByScrollActionTests method setupForTest.

@Before
public void setupForTest() {
    // Fill the context with something random so we can make sure we inherited it appropriately.
    expectedHeaders.clear();
    expectedHeaders.put(randomSimpleString(random()), randomSimpleString(random()));
    setupClient(new TestThreadPool(getTestName()));
    firstSearchRequest = new SearchRequest();
    testRequest = new DummyAbstractBulkByScrollRequest(firstSearchRequest);
    listener = new PlainActionFuture<>();
    scrollId = null;
    taskManager = new TaskManager(Settings.EMPTY);
    testTask = (WorkingBulkByScrollTask) taskManager.register("don'tcare", "hereeither", testRequest);
    localNode = new DiscoveryNode("thenode", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    taskId = new TaskId(localNode.getId(), testTask.getId());
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TaskManager(org.elasticsearch.tasks.TaskManager) TaskId(org.elasticsearch.tasks.TaskId) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 99 with SearchRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.

the class BulkByScrollParallelizationHelperTests method testSliceIntoSubRequests.

public void testSliceIntoSubRequests() throws IOException {
    SearchRequest searchRequest = randomSearchRequest(() -> randomSearchSourceBuilder(() -> null, () -> null, () -> null, () -> emptyList(), () -> null));
    if (searchRequest.source() != null) {
        // Clear the slice builder if there is one set. We can't call sliceIntoSubRequests if it is.
        searchRequest.source().slice(null);
    }
    int times = between(2, 100);
    String field = randomBoolean() ? UidFieldMapper.NAME : randomAsciiOfLength(5);
    int currentSliceId = 0;
    for (SearchRequest slice : sliceIntoSubRequests(searchRequest, field, times)) {
        assertEquals(field, slice.source().slice().getField());
        assertEquals(currentSliceId, slice.source().slice().getId());
        assertEquals(times, slice.source().slice().getMax());
        // If you clear the slice then the slice should be the same request as the parent request
        slice.source().slice(null);
        if (searchRequest.source() == null) {
            // Except that adding the slice might have added an empty builder
            searchRequest.source(new SearchSourceBuilder());
        }
        assertEquals(searchRequest, slice);
        currentSliceId++;
    }
}
Also used : RandomSearchRequestGenerator.randomSearchRequest(org.elasticsearch.search.RandomSearchRequestGenerator.randomSearchRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) RandomSearchRequestGenerator.randomSearchSourceBuilder(org.elasticsearch.search.RandomSearchRequestGenerator.randomSearchSourceBuilder)

Example 100 with SearchRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.

the class DeleteByQueryRequestTests method testTypesGetter.

public void testTypesGetter() {
    int numTypes = between(1, 50);
    String[] types = new String[numTypes];
    for (int i = 0; i < numTypes; i++) {
        types[i] = randomSimpleString(random(), 1, 30);
    }
    SearchRequest searchRequest = new SearchRequest();
    searchRequest.types(types);
    DeleteByQueryRequest request = new DeleteByQueryRequest(searchRequest);
    assertArrayEquals(request.types(), types);
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) TestUtil.randomSimpleString(org.apache.lucene.util.TestUtil.randomSimpleString)

Aggregations

SearchRequest (org.elasticsearch.action.search.SearchRequest)156 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)81 SearchResponse (org.elasticsearch.action.search.SearchResponse)69 Test (org.junit.Test)37 IOException (java.io.IOException)31 SearchHit (org.elasticsearch.search.SearchHit)25 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)22 ArrayList (java.util.ArrayList)21 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)21 HashMap (java.util.HashMap)18 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)17 List (java.util.List)16 SearchHits (org.elasticsearch.search.SearchHits)15 Pipeline (com.hazelcast.jet.pipeline.Pipeline)14 Map (java.util.Map)13 Matchers.containsString (org.hamcrest.Matchers.containsString)12 SearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse)11 SearchSourceBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder)11 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)10 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)10