Search in sources :

Example 26 with SearchRequest

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

the class RemoteRequestBuildersTests method testIntialSearchPath.

public void testIntialSearchPath() {
    SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
    assertEquals("/_search", initialSearchPath(searchRequest));
    searchRequest.indices("a");
    searchRequest.types("b");
    assertEquals("/a/b/_search", initialSearchPath(searchRequest));
    searchRequest.indices("a", "b");
    searchRequest.types("c", "d");
    assertEquals("/a,b/c,d/_search", initialSearchPath(searchRequest));
    searchRequest.indices("cat,");
    expectBadStartRequest(searchRequest, "Index", ",", "cat,");
    searchRequest.indices("cat,", "dog");
    expectBadStartRequest(searchRequest, "Index", ",", "cat,");
    searchRequest.indices("dog", "cat,");
    expectBadStartRequest(searchRequest, "Index", ",", "cat,");
    searchRequest.indices("cat/");
    expectBadStartRequest(searchRequest, "Index", "/", "cat/");
    searchRequest.indices("cat/", "dog");
    expectBadStartRequest(searchRequest, "Index", "/", "cat/");
    searchRequest.indices("dog", "cat/");
    expectBadStartRequest(searchRequest, "Index", "/", "cat/");
    searchRequest.indices("ok");
    searchRequest.types("cat,");
    expectBadStartRequest(searchRequest, "Type", ",", "cat,");
    searchRequest.types("cat,", "dog");
    expectBadStartRequest(searchRequest, "Type", ",", "cat,");
    searchRequest.types("dog", "cat,");
    expectBadStartRequest(searchRequest, "Type", ",", "cat,");
    searchRequest.types("cat/");
    expectBadStartRequest(searchRequest, "Type", "/", "cat/");
    searchRequest.types("cat/", "dog");
    expectBadStartRequest(searchRequest, "Type", "/", "cat/");
    searchRequest.types("dog", "cat/");
    expectBadStartRequest(searchRequest, "Type", "/", "cat/");
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 27 with SearchRequest

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

the class RestReindexActionTests method testReindexFromRemoteRequestParsing.

public void testReindexFromRemoteRequestParsing() throws IOException {
    BytesReference request;
    try (XContentBuilder b = JsonXContent.contentBuilder()) {
        b.startObject();
        {
            b.startObject("source");
            {
                b.startObject("remote");
                {
                    b.field("host", "http://localhost:9200");
                }
                b.endObject();
                b.field("index", "source");
            }
            b.endObject();
            b.startObject("dest");
            {
                b.field("index", "dest");
            }
            b.endObject();
        }
        b.endObject();
        request = b.bytes();
    }
    try (XContentParser p = createParser(JsonXContent.jsonXContent, request)) {
        ReindexRequest r = new ReindexRequest(new SearchRequest(), new IndexRequest());
        RestReindexAction.PARSER.parse(p, r, null);
        assertEquals("localhost", r.getRemoteInfo().getHost());
        assertArrayEquals(new String[] { "source" }, r.getSearchRequest().indices());
    }
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) SearchRequest(org.elasticsearch.action.search.SearchRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 28 with SearchRequest

use of org.graylog.shaded.elasticsearch7.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 29 with SearchRequest

use of org.graylog.shaded.elasticsearch7.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 30 with SearchRequest

use of org.graylog.shaded.elasticsearch7.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)

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