use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.ClearScrollRequest 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.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.ClearScrollRequest 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;
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.ClearScrollRequest in project elasticsearch by elastic.
the class ClientScrollableHitSource method clearScroll.
@Override
public void clearScroll(String scrollId, Runnable onCompletion) {
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
clearScrollRequest.addScrollId(scrollId);
/*
* Unwrap the client so we don't set our task as the parent. If we *did* set our ID then the clear scroll would be cancelled as
* if this task is cancelled. But we want to clear the scroll regardless of whether or not the main request was cancelled.
*/
client.unwrap().clearScroll(clearScrollRequest, new ActionListener<ClearScrollResponse>() {
@Override
public void onResponse(ClearScrollResponse response) {
logger.debug("Freed [{}] contexts", response.getNumFreed());
onCompletion.run();
}
@Override
public void onFailure(Exception e) {
logger.warn((Supplier<?>) () -> new ParameterizedMessage("Failed to clear scroll [{}]", scrollId), e);
onCompletion.run();
}
});
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.ClearScrollRequest in project elasticsearch by elastic.
the class RestClearScrollActionTests method testParseClearScrollRequestWithUnknownParamThrowsException.
public void testParseClearScrollRequestWithUnknownParamThrowsException() throws Exception {
XContentParser invalidContent = createParser(XContentFactory.jsonBuilder().startObject().array("scroll_id", "value_1", "value_2").field("unknown", "keyword").endObject());
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
Exception e = expectThrows(IllegalArgumentException.class, () -> RestClearScrollAction.buildFromContent(invalidContent, clearScrollRequest));
assertThat(e.getMessage(), startsWith("Unknown parameter [unknown]"));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.ClearScrollRequest in project sonarqube by SonarSource.
the class ViewIndex method findAllViewUuids.
public List<String> findAllViewUuids() {
SearchRequest esSearch = EsClient.prepareSearch(ViewIndexDefinition.TYPE_VIEW).source(new SearchSourceBuilder().sort("_doc", SortOrder.ASC).fetchSource(false).size(100).query(matchAllQuery())).scroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES));
SearchResponse response = esClient.search(esSearch);
List<String> result = new ArrayList<>();
while (true) {
List<SearchHit> hits = newArrayList(response.getHits());
for (SearchHit hit : hits) {
result.add(hit.getId());
}
String scrollId = response.getScrollId();
response = esClient.scroll(new SearchScrollRequest().scrollId(scrollId).scroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES)));
// Break condition: No hits are returned
if (response.getHits().getHits().length == 0) {
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
clearScrollRequest.addScrollId(scrollId);
esClient.clearScroll(clearScrollRequest);
break;
}
}
return result;
}
Aggregations