|
6 | 6 | package org.elasticsearch.xpack.ml.integration; |
7 | 7 |
|
8 | 8 | import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest; |
| 9 | +import org.elasticsearch.action.get.GetResponse; |
9 | 10 | import org.elasticsearch.action.search.SearchResponse; |
10 | 11 | import org.elasticsearch.client.Client; |
11 | 12 | import org.elasticsearch.cluster.ClusterModule; |
@@ -342,21 +343,17 @@ protected void waitForecastToFinish(String jobId, String forecastId) throws Exce |
342 | 343 | } |
343 | 344 |
|
344 | 345 | protected ForecastRequestStats getForecastStats(String jobId, String forecastId) { |
345 | | - SearchResponse searchResponse = client().prepareSearch(AnomalyDetectorsIndex.jobResultsAliasedName(jobId)) |
346 | | - .setQuery(QueryBuilders.boolQuery() |
347 | | - .filter(QueryBuilders.termQuery(Result.RESULT_TYPE.getPreferredName(), ForecastRequestStats.RESULT_TYPE_VALUE)) |
348 | | - .filter(QueryBuilders.termQuery(Job.ID.getPreferredName(), jobId)) |
349 | | - .filter(QueryBuilders.termQuery(ForecastRequestStats.FORECAST_ID.getPreferredName(), forecastId))) |
| 346 | + GetResponse getResponse = client().prepareGet() |
| 347 | + .setIndex(AnomalyDetectorsIndex.jobResultsAliasedName(jobId)) |
| 348 | + .setId(ForecastRequestStats.documentId(jobId, forecastId)) |
350 | 349 | .execute().actionGet(); |
351 | | - SearchHits hits = searchResponse.getHits(); |
352 | | - if (hits.getTotalHits() == 0) { |
| 350 | + |
| 351 | + if (getResponse.isExists() == false) { |
353 | 352 | return null; |
354 | 353 | } |
355 | | - assertThat(hits.getTotalHits(), equalTo(1L)); |
356 | | - try { |
357 | | - XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( |
| 354 | + try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( |
358 | 355 | NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, |
359 | | - hits.getHits()[0].getSourceRef().streamInput()); |
| 356 | + getResponse.getSourceAsBytesRef().streamInput())) { |
360 | 357 | return ForecastRequestStats.STRICT_PARSER.apply(parser, null); |
361 | 358 | } catch (IOException e) { |
362 | 359 | throw new IllegalStateException(e); |
|
0 commit comments