|
11 | 11 | import org.elasticsearch.ElasticsearchParseException;
|
12 | 12 | import org.elasticsearch.action.ActionListener;
|
13 | 13 | import org.elasticsearch.action.search.SearchRequest;
|
14 |
| -import org.elasticsearch.action.search.SearchResponse; |
15 | 14 | import org.elasticsearch.action.support.ThreadedActionListener;
|
16 | 15 | import org.elasticsearch.client.OriginSettingClient;
|
17 | 16 | import org.elasticsearch.common.unit.TimeValue;
|
|
54 | 53 | import java.util.Objects;
|
55 | 54 | import java.util.concurrent.TimeUnit;
|
56 | 55 |
|
57 |
| -import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN; |
58 |
| -import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin; |
59 |
| - |
60 | 56 | /**
|
61 | 57 | * Removes all results that have expired the configured retention time
|
62 | 58 | * of their respective job. A result is deleted if its timestamp is earlier
|
@@ -162,26 +158,25 @@ private void latestBucketTime(String jobId, ActionListener<Long> listener) {
|
162 | 158 | searchRequest.source(searchSourceBuilder);
|
163 | 159 | searchRequest.indicesOptions(MlIndicesUtils.addIgnoreUnavailable(SearchRequest.DEFAULT_INDICES_OPTIONS));
|
164 | 160 |
|
165 |
| - executeAsyncWithOrigin(client.threadPool().getThreadContext(), ML_ORIGIN, searchRequest, |
166 |
| - ActionListener.<SearchResponse>wrap( |
167 |
| - response -> { |
168 |
| - SearchHit[] hits = response.getHits().getHits(); |
169 |
| - if (hits.length == 0) { |
170 |
| - // no buckets found |
171 |
| - listener.onResponse(null); |
172 |
| - } else { |
173 |
| - |
174 |
| - try (InputStream stream = hits[0].getSourceRef().streamInput(); |
175 |
| - XContentParser parser = XContentFactory.xContent(XContentType.JSON) |
176 |
| - .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream)) { |
177 |
| - Bucket bucket = Bucket.LENIENT_PARSER.apply(parser, null); |
178 |
| - listener.onResponse(bucket.getTimestamp().getTime()); |
179 |
| - } catch (IOException e) { |
180 |
| - listener.onFailure(new ElasticsearchParseException("failed to parse bucket", e)); |
181 |
| - } |
182 |
| - } |
183 |
| - }, listener::onFailure |
184 |
| - ), client::search); |
| 161 | + client.search(searchRequest, ActionListener.wrap( |
| 162 | + response -> { |
| 163 | + SearchHit[] hits = response.getHits().getHits(); |
| 164 | + if (hits.length == 0) { |
| 165 | + // no buckets found |
| 166 | + listener.onResponse(null); |
| 167 | + } else { |
| 168 | + |
| 169 | + try (InputStream stream = hits[0].getSourceRef().streamInput(); |
| 170 | + XContentParser parser = XContentFactory.xContent(XContentType.JSON) |
| 171 | + .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream)) { |
| 172 | + Bucket bucket = Bucket.LENIENT_PARSER.apply(parser, null); |
| 173 | + listener.onResponse(bucket.getTimestamp().getTime()); |
| 174 | + } catch (IOException e) { |
| 175 | + listener.onFailure(new ElasticsearchParseException("failed to parse bucket", e)); |
| 176 | + } |
| 177 | + } |
| 178 | + }, listener::onFailure |
| 179 | + )); |
185 | 180 | }
|
186 | 181 |
|
187 | 182 | private void auditResultsWereDeleted(String jobId, long cutoffEpochMs) {
|
|
0 commit comments