|
@@ -59,6 +59,11 @@ import org.elasticsearch.xpack.core.ml.job.persistence.ElasticsearchMappings;
|
|
|
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.CategorizerState;
|
|
|
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot;
|
|
|
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.Quantiles;
|
|
|
+import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord;
|
|
|
+import org.elasticsearch.xpack.core.ml.job.results.Bucket;
|
|
|
+import org.elasticsearch.xpack.core.ml.job.results.BucketInfluencer;
|
|
|
+import org.elasticsearch.xpack.core.ml.job.results.Influencer;
|
|
|
+import org.elasticsearch.xpack.core.ml.job.results.ModelPlot;
|
|
|
import org.elasticsearch.xpack.core.ml.job.results.Result;
|
|
|
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
|
|
|
import org.elasticsearch.xpack.core.security.user.XPackUser;
|
|
@@ -185,14 +190,25 @@ public class JobDataDeleter {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Asynchronously delete all result types (Buckets, Records, Influencers) from {@code cutOffTime}
|
|
|
+ * Asynchronously delete all result types (Buckets, Records, Influencers) from {@code cutOffTime}.
|
|
|
+ * Forecasts are <em>not</em> deleted, as they will not be automatically regenerated after
|
|
|
+ * restarting a datafeed following a model snapshot reversion.
|
|
|
*
|
|
|
* @param cutoffEpochMs Results at and after this time will be deleted
|
|
|
* @param listener Response listener
|
|
|
*/
|
|
|
public void deleteResultsFromTime(long cutoffEpochMs, ActionListener<Boolean> listener) {
|
|
|
QueryBuilder query = QueryBuilders.boolQuery()
|
|
|
- .filter(QueryBuilders.existsQuery(Result.RESULT_TYPE.getPreferredName()))
|
|
|
+ .filter(
|
|
|
+ QueryBuilders.termsQuery(
|
|
|
+ Result.RESULT_TYPE.getPreferredName(),
|
|
|
+ AnomalyRecord.RESULT_TYPE_VALUE,
|
|
|
+ Bucket.RESULT_TYPE_VALUE,
|
|
|
+ BucketInfluencer.RESULT_TYPE_VALUE,
|
|
|
+ Influencer.RESULT_TYPE_VALUE,
|
|
|
+ ModelPlot.RESULT_TYPE_VALUE
|
|
|
+ )
|
|
|
+ )
|
|
|
.filter(QueryBuilders.rangeQuery(Result.TIMESTAMP.getPreferredName()).gte(cutoffEpochMs));
|
|
|
DeleteByQueryRequest dbqRequest = new DeleteByQueryRequest(AnomalyDetectorsIndex.jobResultsAliasedName(jobId)).setQuery(query)
|
|
|
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
|