use of org.elasticsearch.search.Scroll in project elasticsearch by elastic.
the class SearchSliceIT method testDocIdSort.
public void testDocIdSort() throws Exception {
int numShards = setupIndex(true);
SearchResponse sr = client().prepareSearch("test").setQuery(matchAllQuery()).setSize(0).get();
int numDocs = (int) sr.getHits().getTotalHits();
assertThat(numDocs, equalTo(NUM_DOCS));
int max = randomIntBetween(2, numShards * 3);
for (String field : new String[] { "_uid", "random_int", "static_int" }) {
int fetchSize = randomIntBetween(10, 100);
SearchRequestBuilder request = client().prepareSearch("test").setQuery(matchAllQuery()).setScroll(new Scroll(TimeValue.timeValueSeconds(10))).setSize(fetchSize).addSort(SortBuilders.fieldSort("_doc"));
assertSearchSlicesWithScroll(request, field, max);
}
}
use of org.elasticsearch.search.Scroll in project elasticsearch by elastic.
the class SearchSliceIT method testInvalidFields.
public void testInvalidFields() throws Exception {
setupIndex(false);
SearchPhaseExecutionException exc = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch("test").setQuery(matchAllQuery()).setScroll(new Scroll(TimeValue.timeValueSeconds(10))).slice(new SliceBuilder("invalid_random_int", 0, 10)).get());
Throwable rootCause = findRootCause(exc);
assertThat(rootCause.getClass(), equalTo(IllegalArgumentException.class));
assertThat(rootCause.getMessage(), startsWith("cannot load numeric doc values"));
exc = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch("test").setQuery(matchAllQuery()).setScroll(new Scroll(TimeValue.timeValueSeconds(10))).slice(new SliceBuilder("invalid_random_kw", 0, 10)).get());
rootCause = findRootCause(exc);
assertThat(rootCause.getClass(), equalTo(IllegalArgumentException.class));
assertThat(rootCause.getMessage(), startsWith("cannot load numeric doc values"));
}
use of org.elasticsearch.search.Scroll in project elasticsearch by elastic.
the class RestSearchScrollAction method buildFromContent.
public static void buildFromContent(XContentParser parser, SearchScrollRequest searchScrollRequest) throws IOException {
if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
throw new IllegalArgumentException("Malformed content, must start with an object");
} else {
XContentParser.Token token;
String currentFieldName = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if ("scroll_id".equals(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
searchScrollRequest.scrollId(parser.text());
} else if ("scroll".equals(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
searchScrollRequest.scroll(new Scroll(TimeValue.parseTimeValue(parser.text(), null, "scroll")));
} else {
throw new IllegalArgumentException("Unknown parameter [" + currentFieldName + "] in request body or parameter is of the wrong type[" + token + "] ");
}
}
}
}
Aggregations