@@ -490,20 +490,6 @@ private <T, U> T parseSearchHit(SearchHit hit, BiFunction<XContentParser, U, T>
490
490
}
491
491
}
492
492
493
- private <T , U > T parseGetHit (GetResponse getResponse , BiFunction <XContentParser , U , T > objectParser ,
494
- Consumer <Exception > errorHandler ) {
495
- BytesReference source = getResponse .getSourceAsBytesRef ();
496
-
497
- try (InputStream stream = source .streamInput ();
498
- XContentParser parser = XContentFactory .xContent (XContentType .JSON )
499
- .createParser (NamedXContentRegistry .EMPTY , LoggingDeprecationHandler .INSTANCE , stream )) {
500
- return objectParser .apply (parser , null );
501
- } catch (IOException e ) {
502
- errorHandler .accept (new ElasticsearchParseException ("failed to parse " + getResponse .getType (), e ));
503
- return null ;
504
- }
505
- }
506
-
507
493
/**
508
494
* Search for buckets with the parameters in the {@link BucketsQueryBuilder}
509
495
* Uses the internal client, so runs as the _xpack user
@@ -957,19 +943,6 @@ private <U, T> void searchSingleResult(String jobId, String resultDescription, S
957
943
), client ::search );
958
944
}
959
945
960
- private <U , T > void getResult (String jobId , String resultDescription , GetRequest get , BiFunction <XContentParser , U , T > objectParser ,
961
- Consumer <Result <T >> handler , Consumer <Exception > errorHandler , Supplier <T > notFoundSupplier ) {
962
-
963
- executeAsyncWithOrigin (client .threadPool ().getThreadContext (), ML_ORIGIN , get , ActionListener .<GetResponse >wrap (getDocResponse -> {
964
- if (getDocResponse .isExists ()) {
965
- handler .accept (new Result <>(getDocResponse .getIndex (), parseGetHit (getDocResponse , objectParser , errorHandler )));
966
- } else {
967
- LOGGER .trace ("No {} for job with id {}" , resultDescription , jobId );
968
- handler .accept (new Result <>(null , notFoundSupplier .get ()));
969
- }
970
- }, errorHandler ), client ::get );
971
- }
972
-
973
946
private SearchRequestBuilder createLatestModelSizeStatsSearch (String indexName ) {
974
947
return client .prepareSearch (indexName )
975
948
.setSize (1 )
@@ -1115,11 +1088,14 @@ public void scheduledEvents(ScheduledEventsQueryBuilder query, ActionListener<Qu
1115
1088
public void getForecastRequestStats (String jobId , String forecastId , Consumer <ForecastRequestStats > handler ,
1116
1089
Consumer <Exception > errorHandler ) {
1117
1090
String indexName = AnomalyDetectorsIndex .jobResultsAliasedName (jobId );
1118
- GetRequest getRequest = new GetRequest (indexName , ElasticsearchMappings .DOC_TYPE ,
1119
- ForecastRequestStats .documentId (jobId , forecastId ));
1120
-
1121
- getResult (jobId , ForecastRequestStats .RESULTS_FIELD .getPreferredName (), getRequest , ForecastRequestStats .LENIENT_PARSER ,
1122
- result -> handler .accept (result .result ), errorHandler , () -> null );
1091
+ SearchRequestBuilder forecastSearch = client .prepareSearch (indexName )
1092
+ .setQuery (QueryBuilders .idsQuery ().addIds (ForecastRequestStats .documentId (jobId , forecastId )));
1093
+
1094
+ searchSingleResult (jobId ,
1095
+ ForecastRequestStats .RESULTS_FIELD .getPreferredName (),
1096
+ forecastSearch ,
1097
+ ForecastRequestStats .LENIENT_PARSER ,result -> handler .accept (result .result ),
1098
+ errorHandler , () -> null );
1123
1099
}
1124
1100
1125
1101
public void getForecastStats (String jobId , Consumer <ForecastStats > handler , Consumer <Exception > errorHandler ) {
0 commit comments