use of org.elasticsearch.action.search.SearchScrollRequest in project elasticsearch by elastic.
the class RestSearchScrollAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
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")));
}
request.withContentOrSourceParamParserOrNull(xContentParser -> {
if (xContentParser != null) {
try {
buildFromContent(xContentParser, searchScrollRequest);
} catch (IOException e) {
throw new IllegalArgumentException("Failed to parse request body", e);
}
}
});
return channel -> client.searchScroll(searchScrollRequest, new RestStatusToXContentListener<>(channel));
}
use of org.elasticsearch.action.search.SearchScrollRequest in project elasticsearch by elastic.
the class RestSearchScrollActionTests method testParseSearchScrollRequest.
public void testParseSearchScrollRequest() throws Exception {
XContentParser content = createParser(XContentFactory.jsonBuilder().startObject().field("scroll_id", "SCROLL_ID").field("scroll", "1m").endObject());
SearchScrollRequest searchScrollRequest = new SearchScrollRequest();
RestSearchScrollAction.buildFromContent(content, searchScrollRequest);
assertThat(searchScrollRequest.scrollId(), equalTo("SCROLL_ID"));
assertThat(searchScrollRequest.scroll().keepAlive(), equalTo(TimeValue.parseTimeValue("1m", null, "scroll")));
}
use of org.elasticsearch.action.search.SearchScrollRequest in project graylog2-server by Graylog2.
the class ScrollResultES7 method nextSearchResult.
private SearchResponse nextSearchResult() throws IOException {
final SearchScrollRequest scrollRequest = new SearchScrollRequest(this.scrollId);
scrollRequest.scroll(TimeValue.parseTimeValue(this.scroll, DEFAULT_SCROLL, "scroll time"));
return client.executeWithIOException((c, requestOptions) -> c.scroll(scrollRequest, requestOptions), "Unable to retrieve next chunk from search: ");
}
use of org.elasticsearch.action.search.SearchScrollRequest in project sonarqube by SonarSource.
the class EsTester method getDocuments.
private List<SearchHit> getDocuments(SearchRequest req) {
req.scroll(new TimeValue(60000));
req.source().size(100).sort("_doc", SortOrder.ASC);
SearchResponse response = ES_REST_CLIENT.search(req);
List<SearchHit> result = newArrayList();
while (true) {
Iterables.addAll(result, response.getHits());
response = ES_REST_CLIENT.scroll(new SearchScrollRequest(response.getScrollId()).scroll(new TimeValue(600000)));
// Break condition: No hits are returned
if (response.getHits().getHits().length == 0) {
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
clearScrollRequest.addScrollId(response.getScrollId());
ES_REST_CLIENT.clearScroll(clearScrollRequest);
break;
}
}
return result;
}
use of org.elasticsearch.action.search.SearchScrollRequest in project sonarqube by SonarSource.
the class BulkIndexer method addDeletion.
public void addDeletion(SearchRequest searchRequest) {
// TODO to be replaced by delete_by_query that is back in ES5
searchRequest.scroll(TimeValue.timeValueMinutes(5)).source().sort("_doc", SortOrder.ASC).size(100).fetchSource(false);
// this search is synchronous. An optimization would be to be non-blocking,
// but it requires to tracking pending requests in close().
// Same semaphore can't be reused because of potential deadlock (requires to acquire
// two locks)
SearchResponse searchResponse = esClient.search(searchRequest);
while (true) {
SearchHit[] hits = searchResponse.getHits().getHits();
for (SearchHit hit : hits) {
DocumentField routing = hit.field("_routing");
DeleteRequest deleteRequest = new DeleteRequest(hit.getIndex(), hit.getType(), hit.getId());
if (routing != null) {
deleteRequest.routing(routing.getValue());
}
add(deleteRequest);
}
String scrollId = searchResponse.getScrollId();
if (scrollId == null) {
break;
}
searchResponse = esClient.scroll(new SearchScrollRequest(scrollId).scroll(TimeValue.timeValueMinutes(5)));
if (hits.length == 0) {
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
clearScrollRequest.addScrollId(scrollId);
esClient.clearScroll(clearScrollRequest);
break;
}
}
}
Aggregations