[ML] Reuse encapsulated delete-by-query request
Original commit: elastic/x-pack-elasticsearch@cc0f2ce815
This commit is contained in:
parent
3f73748d14
commit
d140b3028d
|
@ -105,18 +105,16 @@ public class JobDataDeleter {
|
||||||
* Delete all results marked as interim
|
* Delete all results marked as interim
|
||||||
*/
|
*/
|
||||||
public void deleteInterimResults() {
|
public void deleteInterimResults() {
|
||||||
SearchRequest searchRequest = new SearchRequest(AnomalyDetectorsIndex.jobResultsAliasedName(jobId));
|
DeleteByQueryHolder deleteByQueryHolder = new DeleteByQueryHolder(AnomalyDetectorsIndex.jobResultsAliasedName(jobId));
|
||||||
DeleteByQueryRequest request = new DeleteByQueryRequest(searchRequest);
|
deleteByQueryHolder.dbqRequest.setRefresh(false);
|
||||||
request.setRefresh(false);
|
|
||||||
request.setSlices(5);
|
|
||||||
|
|
||||||
searchRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
|
deleteByQueryHolder.searchRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
|
||||||
searchRequest.types(Result.TYPE.getPreferredName());
|
deleteByQueryHolder.searchRequest.types(Result.TYPE.getPreferredName());
|
||||||
QueryBuilder qb = QueryBuilders.termQuery(Bucket.IS_INTERIM.getPreferredName(), true);
|
QueryBuilder qb = QueryBuilders.termQuery(Bucket.IS_INTERIM.getPreferredName(), true);
|
||||||
searchRequest.source(new SearchSourceBuilder().query(new ConstantScoreQueryBuilder(qb)));
|
deleteByQueryHolder.searchRequest.source(new SearchSourceBuilder().query(new ConstantScoreQueryBuilder(qb)));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.execute(XPackDeleteByQueryAction.INSTANCE, request).get();
|
client.execute(XPackDeleteByQueryAction.INSTANCE, deleteByQueryHolder.dbqRequest).get();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("[" + jobId + "] An error occurred while deleting interim results", e);
|
LOGGER.error("[" + jobId + "] An error occurred while deleting interim results", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue