use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class RemoteRequestBuildersTests method testInitialSearchParamsSort.
public void testInitialSearchParamsSort() {
SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
// Test sort:_doc for versions that support it.
Version remoteVersion = Version.fromId(between(Version.V_2_1_0_ID, Version.CURRENT.id));
searchRequest.source().sort("_doc");
assertThat(initialSearchParams(searchRequest, remoteVersion), hasEntry("sort", "_doc:asc"));
// Test search_type scan for versions that don't support sort:_doc.
remoteVersion = Version.fromId(between(0, Version.V_2_1_0_ID - 1));
assertThat(initialSearchParams(searchRequest, remoteVersion), hasEntry("search_type", "scan"));
// Test sorting by some field. Version doesn't matter.
remoteVersion = Version.fromId(between(0, Version.CURRENT.id));
searchRequest.source().sorts().clear();
searchRequest.source().sort("foo");
assertThat(initialSearchParams(searchRequest, remoteVersion), hasEntry("sort", "foo:asc"));
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class RemoteRequestBuildersTests method testInitialSearchEntity.
public void testInitialSearchEntity() throws IOException {
SearchRequest searchRequest = new SearchRequest();
searchRequest.source(new SearchSourceBuilder());
String query = "{\"match_all\":{}}";
HttpEntity entity = initialSearchEntity(searchRequest, new BytesArray(query));
assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue());
assertEquals("{\"query\":" + query + ",\"_source\":true}", Streams.copyToString(new InputStreamReader(entity.getContent(), StandardCharsets.UTF_8)));
// Source filtering is included if set up
searchRequest.source().fetchSource(new String[] { "in1", "in2" }, new String[] { "out" });
entity = initialSearchEntity(searchRequest, new BytesArray(query));
assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue());
assertEquals("{\"query\":" + query + ",\"_source\":{\"includes\":[\"in1\",\"in2\"],\"excludes\":[\"out\"]}}", Streams.copyToString(new InputStreamReader(entity.getContent(), StandardCharsets.UTF_8)));
// Invalid XContent fails
RuntimeException e = expectThrows(RuntimeException.class, () -> initialSearchEntity(searchRequest, new BytesArray("{}, \"trailing\": {}")));
assertThat(e.getCause().getMessage(), containsString("Unexpected character (',' (code 44))"));
e = expectThrows(RuntimeException.class, () -> initialSearchEntity(searchRequest, new BytesArray("{")));
assertThat(e.getCause().getMessage(), containsString("Unexpected end-of-input"));
}
use of 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/");
}
use of 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());
}
}
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;
}
Aggregations