|
30 | 30 | import org.elasticsearch.xpack.core.ml.job.persistence.ElasticsearchMappings;
|
31 | 31 | import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot;
|
32 | 32 | import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshotField;
|
33 |
| -import org.elasticsearch.xpack.core.ml.job.results.Bucket; |
34 |
| -import org.elasticsearch.xpack.core.ml.job.results.Result; |
35 | 33 | import org.elasticsearch.xpack.ml.MachineLearning;
|
36 | 34 | import org.elasticsearch.xpack.ml.utils.MlIndicesUtils;
|
37 | 35 | import org.elasticsearch.xpack.ml.utils.VolatileCursorIterator;
|
@@ -84,20 +82,25 @@ void calcCutoffEpochMs(String jobId, long retentionDays, ActionListener<Long> li
|
84 | 82 |
|
85 | 83 | latestSnapshotTimeStamp(jobId, ActionListener.wrap(
|
86 | 84 | latestTime -> {
|
87 |
| - long cutoff = latestTime - new TimeValue(retentionDays, TimeUnit.DAYS).getMillis(); |
88 |
| - threadedActionListener.onResponse(cutoff); |
| 85 | + if (latestTime == null) { |
| 86 | + threadedActionListener.onResponse(null); |
| 87 | + } else { |
| 88 | + long cutoff = latestTime - new TimeValue(retentionDays, TimeUnit.DAYS).getMillis(); |
| 89 | + threadedActionListener.onResponse(cutoff); |
| 90 | + } |
89 | 91 | },
|
90 | 92 | listener::onFailure
|
91 | 93 | ));
|
92 | 94 | }
|
93 | 95 |
|
94 | 96 | private void latestSnapshotTimeStamp(String jobId, ActionListener<Long> listener) {
|
95 | 97 | SortBuilder<?> sortBuilder = new FieldSortBuilder(ModelSnapshot.TIMESTAMP.getPreferredName()).order(SortOrder.DESC);
|
96 |
| - QueryBuilder bucketType = QueryBuilders.termQuery(Result.RESULT_TYPE.getPreferredName(), Bucket.RESULT_TYPE_VALUE); |
| 98 | + QueryBuilder snapshotQuery = QueryBuilders.boolQuery() |
| 99 | + .filter(QueryBuilders.existsQuery(ModelSnapshot.SNAPSHOT_DOC_COUNT.getPreferredName())); |
97 | 100 |
|
98 | 101 | SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
99 | 102 | searchSourceBuilder.sort(sortBuilder);
|
100 |
| - searchSourceBuilder.query(bucketType); |
| 103 | + searchSourceBuilder.query(snapshotQuery); |
101 | 104 | searchSourceBuilder.size(1);
|
102 | 105 | searchSourceBuilder.trackTotalHits(false);
|
103 | 106 |
|
|
0 commit comments