Search in sources :

Example 96 with SearchRequest

use of 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 97 with SearchRequest

use of 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)

Example 98 with SearchRequest

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

the class RemoteRequestBuildersTests method testInitialSearchParamsMisc.

public void testInitialSearchParamsMisc() {
    SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
    Version remoteVersion = Version.fromId(between(0, Version.CURRENT.id));
    TimeValue scroll = null;
    if (randomBoolean()) {
        scroll = TimeValue.parseTimeValue(randomPositiveTimeValue(), "test");
        searchRequest.scroll(scroll);
    }
    int size = between(0, Integer.MAX_VALUE);
    searchRequest.source().size(size);
    Boolean fetchVersion = null;
    if (randomBoolean()) {
        fetchVersion = randomBoolean();
        searchRequest.source().version(fetchVersion);
    }
    Map<String, String> params = initialSearchParams(searchRequest, remoteVersion);
    assertThat(params, scroll == null ? not(hasKey("scroll")) : hasEntry("scroll", scroll.toString()));
    assertThat(params, hasEntry("size", Integer.toString(size)));
    assertThat(params, fetchVersion == null || fetchVersion == true ? hasEntry("version", null) : not(hasEntry("version", null)));
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Version(org.elasticsearch.Version) Matchers.containsString(org.hamcrest.Matchers.containsString) TimeValue(org.elasticsearch.common.unit.TimeValue) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 99 with SearchRequest

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

the class RemoteRequestBuildersTests method testInitialSearchParamsFields.

public void testInitialSearchParamsFields() {
    SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
    // Test request without any fields
    Version remoteVersion = VersionUtils.randomVersion(random());
    assertThat(initialSearchParams(searchRequest, remoteVersion), not(either(hasKey("stored_fields")).or(hasKey("fields"))));
    // Setup some fields for the next two tests
    searchRequest.source().storedField("_source").storedField("_id");
    // Test stored_fields for versions that support it
    remoteVersion = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0_alpha4, null);
    assertThat(initialSearchParams(searchRequest, remoteVersion), hasEntry("stored_fields", "_source,_id"));
    // Test fields for versions that support it
    remoteVersion = VersionUtils.randomVersionBetween(random(), null, Version.V_5_0_0_alpha3);
    assertThat(initialSearchParams(searchRequest, remoteVersion), hasEntry("fields", "_source,_id"));
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Version(org.elasticsearch.Version) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 100 with SearchRequest

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

the class RemoteScrollableHitSourceTests method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    final ExecutorService directExecutor = EsExecutors.newDirectExecutorService();
    threadPool = new TestThreadPool(getTestName()) {

        @Override
        public ExecutorService executor(String name) {
            return directExecutor;
        }

        @Override
        public ScheduledFuture<?> schedule(TimeValue delay, String name, Runnable command) {
            command.run();
            return null;
        }
    };
    retries = 0;
    searchRequest = new SearchRequest();
    searchRequest.scroll(timeValueMinutes(5));
    searchRequest.source(new SearchSourceBuilder().size(10).version(true).sort("_doc").size(123));
    retriesAllowed = 0;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) ExecutorService(java.util.concurrent.ExecutorService) Matchers.containsString(org.hamcrest.Matchers.containsString) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) TimeValue(org.elasticsearch.common.unit.TimeValue) ScheduledFuture(java.util.concurrent.ScheduledFuture) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) Before(org.junit.Before)

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 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 SearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse)10