Search in sources :

Example 6 with Scroll

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

Example 7 with Scroll

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

Example 8 with Scroll

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 + "] ");
            }
        }
    }
}
Also used : Scroll(org.elasticsearch.search.Scroll) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

Scroll (org.elasticsearch.search.Scroll)8 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 IOException (java.io.IOException)2 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)2 XContentParser (org.elasticsearch.common.xcontent.XContentParser)2 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)1 SearchScrollRequest (org.elasticsearch.action.search.SearchScrollRequest)1 SearchType (org.elasticsearch.action.search.SearchType)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 Settings (org.elasticsearch.common.settings.Settings)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1 TimeValue.parseTimeValue (org.elasticsearch.common.unit.TimeValue.parseTimeValue)1 BigArrays (org.elasticsearch.common.util.BigArrays)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 QueryParseContext (org.elasticsearch.index.query.QueryParseContext)1 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)1