Search in sources :

Example 31 with SearchRequest

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;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 32 with SearchRequest

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());
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest)

Example 33 with SearchRequest

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);
        }
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 34 with 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;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) ArrayList(java.util.ArrayList) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 35 with SearchRequest

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;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest)

Aggregations

SearchRequest (org.elasticsearch.action.search.SearchRequest)69 SearchResponse (org.elasticsearch.action.search.SearchResponse)21 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)13 Matchers.containsString (org.hamcrest.Matchers.containsString)12 IOException (java.io.IOException)10 HashMap (java.util.HashMap)10 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)8 Test (org.junit.Test)7 MultiSearchRequest (org.elasticsearch.action.search.MultiSearchRequest)6 BytesArray (org.elasticsearch.common.bytes.BytesArray)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 XContentParser (org.elasticsearch.common.xcontent.XContentParser)6 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)6 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)6 ArrayList (java.util.ArrayList)5 TestUtil.randomSimpleString (org.apache.lucene.util.TestUtil.randomSimpleString)5 IndexRequest (org.elasticsearch.action.index.IndexRequest)5 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)5 BytesReference (org.elasticsearch.common.bytes.BytesReference)5 List (java.util.List)4