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++;
}
}
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);
}
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)));
}
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"));
}
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;
}
Aggregations