use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class ReindexRequestTests method newRequest.
@Override
protected ReindexRequest newRequest() {
ReindexRequest reindex = new ReindexRequest(new SearchRequest(), new IndexRequest());
reindex.getSearchRequest().indices("source");
reindex.getDestination().index("dest");
return reindex;
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class SearchRequestTests method testIllegalArguments.
public void testIllegalArguments() {
SearchRequest searchRequest = new SearchRequest();
assertNotNull(searchRequest.indices());
assertNotNull(searchRequest.indicesOptions());
assertNotNull(searchRequest.types());
assertNotNull(searchRequest.searchType());
NullPointerException e = expectThrows(NullPointerException.class, () -> searchRequest.indices((String[]) null));
assertEquals("indices must not be null", e.getMessage());
e = expectThrows(NullPointerException.class, () -> searchRequest.indices((String) null));
assertEquals("index must not be null", e.getMessage());
e = expectThrows(NullPointerException.class, () -> searchRequest.indicesOptions(null));
assertEquals("indicesOptions must not be null", e.getMessage());
e = expectThrows(NullPointerException.class, () -> searchRequest.types((String[]) null));
assertEquals("types must not be null", e.getMessage());
e = expectThrows(NullPointerException.class, () -> searchRequest.types((String) null));
assertEquals("type must not be null", e.getMessage());
e = expectThrows(NullPointerException.class, () -> searchRequest.searchType((SearchType) null));
assertEquals("searchType must not be null", e.getMessage());
e = expectThrows(NullPointerException.class, () -> searchRequest.source(null));
assertEquals("source must not be null", e.getMessage());
e = expectThrows(NullPointerException.class, () -> searchRequest.scroll((TimeValue) null));
assertEquals("keepAlive must not be null", e.getMessage());
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class SearchRequestTests method testSerialization.
public void testSerialization() throws Exception {
SearchRequest searchRequest = createSearchRequest();
try (BytesStreamOutput output = new BytesStreamOutput()) {
searchRequest.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
SearchRequest deserializedRequest = new SearchRequest();
deserializedRequest.readFrom(in);
assertEquals(deserializedRequest, searchRequest);
assertEquals(deserializedRequest.hashCode(), searchRequest.hashCode());
assertNotSame(deserializedRequest, searchRequest);
}
}
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class SearchRequestTests method mutate.
private SearchRequest mutate(SearchRequest searchRequest) throws IOException {
SearchRequest mutation = copyRequest(searchRequest);
List<Runnable> mutators = new ArrayList<>();
mutators.add(() -> mutation.indices(ArrayUtils.concat(searchRequest.indices(), new String[] { randomAsciiOfLength(10) })));
mutators.add(() -> mutation.indicesOptions(randomValueOtherThan(searchRequest.indicesOptions(), () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()))));
mutators.add(() -> mutation.types(ArrayUtils.concat(searchRequest.types(), new String[] { randomAsciiOfLength(10) })));
mutators.add(() -> mutation.preference(randomValueOtherThan(searchRequest.preference(), () -> randomAsciiOfLengthBetween(3, 10))));
mutators.add(() -> mutation.routing(randomValueOtherThan(searchRequest.routing(), () -> randomAsciiOfLengthBetween(3, 10))));
mutators.add(() -> mutation.requestCache((randomValueOtherThan(searchRequest.requestCache(), () -> randomBoolean()))));
mutators.add(() -> mutation.scroll(randomValueOtherThan(searchRequest.scroll(), () -> new Scroll(new TimeValue(randomNonNegativeLong() % 100000)))));
mutators.add(() -> mutation.searchType(randomValueOtherThan(searchRequest.searchType(), () -> randomFrom(SearchType.values()))));
mutators.add(() -> mutation.source(randomValueOtherThan(searchRequest.source(), this::createSearchSourceBuilder)));
randomFrom(mutators).run();
return mutation;
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class SearchRequestTests method copyRequest.
private static SearchRequest copyRequest(SearchRequest searchRequest) throws IOException {
SearchRequest result = new SearchRequest();
result.indices(searchRequest.indices());
result.indicesOptions(searchRequest.indicesOptions());
result.types(searchRequest.types());
result.searchType(searchRequest.searchType());
result.preference(searchRequest.preference());
result.routing(searchRequest.routing());
result.requestCache(searchRequest.requestCache());
result.scroll(searchRequest.scroll());
if (searchRequest.source() != null) {
result.source(searchRequest.source());
}
return result;
}
Aggregations