org.elasticsearch.action.search.SearchScrollRequest Java Examples

The following examples show how to use org.elasticsearch.action.search.SearchScrollRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElasticsearchClient.java    From presto with Apache License 2.0 6 votes vote down vote up
public SearchResponse nextPage(String scrollId)
{
    LOG.debug("Next page: %s", scrollId);

    SearchScrollRequest request = new SearchScrollRequest(scrollId)
            .scroll(new TimeValue(scrollTimeout.toMillis()));

    long start = System.nanoTime();
    try {
        return client.searchScroll(request);
    }
    catch (IOException e) {
        throw new PrestoException(ELASTICSEARCH_CONNECTION_ERROR, e);
    }
    finally {
        nextPageStats.add(Duration.nanosSince(start));
    }
}
 
Example #2
Source File: ElasticsearchIndexer.java    From datashare with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Stream<? extends Entity> scroll(int numSlice, int nbSlices) throws IOException {
    sourceBuilder.query(boolQuery);
    if (nbSlices > 1) {
        sourceBuilder.slice(new SliceBuilder(numSlice, nbSlices));
    }
    SearchResponse search;
    if (scrollId == null) {
        SearchRequest searchRequest = new SearchRequest(new String[]{indexName}, sourceBuilder).scroll(KEEP_ALIVE);
        searchRequest.types(config.indexType);
        search = client.search(searchRequest);
        scrollId = search.getScrollId();
        totalHits = search.getHits().totalHits;
    } else {
        search = client.searchScroll(new SearchScrollRequest(scrollId).scroll(KEEP_ALIVE));
        scrollId = search.getScrollId();
    }
    return resultStream(this.cls, () -> search.getHits().iterator());
}
 
Example #3
Source File: RestSearchScrollAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String scrollId = request.param("scroll_id");
    SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
    searchScrollRequest.scrollId(scrollId);
    String scroll = request.param("scroll");
    if (scroll != null) {
        searchScrollRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll")));
    }

    if (RestActions.hasBodyContent(request)) {
        XContentType type = XContentFactory.xContentType(RestActions.getRestContent(request));
        if (type == null) {
            if (scrollId == null) {
                scrollId = RestActions.getRestContent(request).toUtf8();
                searchScrollRequest.scrollId(scrollId);
            }
        } else {
            // NOTE: if rest request with xcontent body has request parameters, these parameters override xcontent values
            buildFromContent(RestActions.getRestContent(request), searchScrollRequest);
        }
    }
    client.searchScroll(searchScrollRequest, new RestStatusToXContentListener<SearchResponse>(channel));
}
 
Example #4
Source File: RestSearchScrollAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static void buildFromContent(BytesReference content, SearchScrollRequest searchScrollRequest) {
    try (XContentParser parser = XContentHelper.createParser(content)) {
        if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
            throw new IllegalArgumentException("Malforrmed 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 + "] ");
                }
            }
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to parse request body", e);
    }
}
 
Example #5
Source File: ESRichClientImp.java    From blue-marlin with Apache License 2.0 5 votes vote down vote up
@Override
public ESResponse searchScroll(SearchScrollRequest searchScrollRequest) throws IOException, JSONException
{
    SearchResponse response = rhlclient.searchScroll(searchScrollRequest);
    LOGGER.debug("response={}", CommonUtil.removeEscapingCharacters(response.toString()));
    Map<String, Object> map = QueryUtil.toMap(QueryUtil.extractAggregationValue(response));
    return new ESResponse(response, map);
}
 
Example #6
Source File: ScrollSpout.java    From storm-crawler with Apache License 2.0 5 votes vote down vote up
@Override
protected void populateBuffer() {
    if (hasFinished) {
        Utils.sleep(10);
        return;
    }

    // initial request
    if (scrollId == null) {
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(QueryBuilders.matchAllQuery());
        searchSourceBuilder.size(maxURLsPerBucket * maxBucketNum);
        SearchRequest searchRequest = new SearchRequest(indexName);
        searchRequest.source(searchSourceBuilder);
        searchRequest.scroll(TimeValue.timeValueMinutes(5L));

        if (shardID != -1) {
            searchRequest.preference("_shards:" + shardID);
        }

        isInQuery.set(true);
        client.searchAsync(searchRequest, RequestOptions.DEFAULT, this);

        // dump query to log
        LOG.debug("{} ES query {}", logIdprefix, searchRequest.toString());
        return;
    }

    SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId);
    scrollRequest.scroll(TimeValue.timeValueMinutes(5L));

    isInQuery.set(true);
    client.scrollAsync(scrollRequest, RequestOptions.DEFAULT, this);
    // dump query to log
    LOG.debug("{} ES query {}", logIdprefix, scrollRequest.toString());
}
 
Example #7
Source File: ScrolledSearch.java    From james-project with Apache License 2.0 5 votes vote down vote up
private Mono<SearchResponse> buildRequest(Optional<String> scrollId) {
    return scrollId.map(id ->
        client.scroll(
            new SearchScrollRequest()
                .scrollId(scrollId.get())
                .scroll(TIMEOUT),
            RequestOptions.DEFAULT))
        .orElseGet(() -> client.search(searchRequest, RequestOptions.DEFAULT));
}
 
Example #8
Source File: TransportConnection.java    From heroic with Apache License 2.0 5 votes vote down vote up
@Override
public void searchScroll(
    @NotNull String scrollId,
    @NotNull TimeValue timeout,
    @NotNull ActionListener<SearchResponse> listener
) {
    SearchScrollRequest request = new SearchScrollRequest(scrollId).scroll(timeout);
    client.searchScroll(request, listener);
}
 
Example #9
Source File: ShardFetchRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public ShardFetchRequest(SearchScrollRequest request, long id, IntArrayList list, ScoreDoc lastEmittedDoc) {
    super(request);
    this.id = id;
    this.docIds = list.buffer;
    this.size = list.size();
    this.lastEmittedDoc = lastEmittedDoc;
}
 
Example #10
Source File: ClientWithStats.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public ActionFuture<SearchResponse> searchScroll(SearchScrollRequest request) {
	return wrapped.searchScroll(request);
}
 
Example #11
Source File: ClientWithStats.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void searchScroll(SearchScrollRequest request, ActionListener<SearchResponse> listener) {
	wrapped.searchScroll(request, listener);
}
 
Example #12
Source File: InternalScrollSearchRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public InternalScrollSearchRequest(SearchScrollRequest request, long id) {
    super(request);
    this.id = id;
    this.scroll = request.scroll();
}
 
Example #13
Source File: ReactorElasticSearchClient.java    From james-project with Apache License 2.0 4 votes vote down vote up
public Mono<SearchResponse> scroll(SearchScrollRequest searchScrollRequest, RequestOptions options) {
    return toReactor(listener -> client.scrollAsync(searchScrollRequest, options, listener));
}
 
Example #14
Source File: FessEsClient.java    From fess with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<SearchResponse> searchScroll(final SearchScrollRequest request) {
    return client.searchScroll(request);
}
 
Example #15
Source File: FessEsClient.java    From fess with Apache License 2.0 4 votes vote down vote up
@Override
public void searchScroll(final SearchScrollRequest request, final ActionListener<SearchResponse> listener) {
    client.searchScroll(request, listener);
}
 
Example #16
Source File: SearchScrollRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public SearchScrollRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new SearchScrollRequest(), jsonToString, stringToJson);
}
 
Example #17
Source File: SearchScrollRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<SearchResponse> doExecute(SearchScrollRequest request) {
    return client.searchScroll(request);
}
 
Example #18
Source File: SearchScrollRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected XContentBuilder toXContent(SearchScrollRequest request, SearchResponse response, XContentBuilder builder) throws IOException {
    return super.toXContent(request, response, builder).endObject();
}
 
Example #19
Source File: Requests.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a search scroll request allowing to continue searching a previous search request.
 *
 * @param scrollId The scroll id representing the scrollable search
 * @return The search scroll request
 * @see org.elasticsearch.client.Client#searchScroll(org.elasticsearch.action.search.SearchScrollRequest)
 */
public static SearchScrollRequest searchScrollRequest(String scrollId) {
    return new SearchScrollRequest(scrollId);
}
 
Example #20
Source File: ESClient.java    From blue-marlin with Apache License 2.0 2 votes vote down vote up
/**
 *  This methods returns result of search-scroll query on elasticsearch. search-scroll is used to read
 *  huge set of data.
 *
 * @param searchScrollRequest
 * @return
 * @throws IOException
 * @throws JSONException
 */
ESResponse searchScroll(SearchScrollRequest searchScrollRequest) throws IOException, JSONException;