@@ -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
@@ -953,19 +939,6 @@ private <U, T> void searchSingleResult(String jobId, String resultDescription, S
953
939
), client ::search );
954
940
}
955
941
956
- private <U , T > void getResult (String jobId , String resultDescription , GetRequest get , BiFunction <XContentParser , U , T > objectParser ,
957
- Consumer <Result <T >> handler , Consumer <Exception > errorHandler , Supplier <T > notFoundSupplier ) {
958
-
959
- executeAsyncWithOrigin (client .threadPool ().getThreadContext (), ML_ORIGIN , get , ActionListener .<GetResponse >wrap (getDocResponse -> {
960
- if (getDocResponse .isExists ()) {
961
- handler .accept (new Result <>(getDocResponse .getIndex (), parseGetHit (getDocResponse , objectParser , errorHandler )));
962
- } else {
963
- LOGGER .trace ("No {} for job with id {}" , resultDescription , jobId );
964
- handler .accept (new Result <>(null , notFoundSupplier .get ()));
965
- }
966
- }, errorHandler ), client ::get );
967
- }
968
-
969
942
private SearchRequestBuilder createLatestModelSizeStatsSearch (String indexName ) {
970
943
return client .prepareSearch (indexName )
971
944
.setSize (1 )
@@ -1110,11 +1083,14 @@ public void scheduledEvents(ScheduledEventsQueryBuilder query, ActionListener<Qu
1110
1083
public void getForecastRequestStats (String jobId , String forecastId , Consumer <ForecastRequestStats > handler ,
1111
1084
Consumer <Exception > errorHandler ) {
1112
1085
String indexName = AnomalyDetectorsIndex .jobResultsAliasedName (jobId );
1113
- GetRequest getRequest = new GetRequest (indexName , ElasticsearchMappings .DOC_TYPE ,
1114
- ForecastRequestStats .documentId (jobId , forecastId ));
1115
-
1116
- getResult (jobId , ForecastRequestStats .RESULTS_FIELD .getPreferredName (), getRequest , ForecastRequestStats .LENIENT_PARSER ,
1117
- result -> handler .accept (result .result ), errorHandler , () -> null );
1086
+ SearchRequestBuilder forecastSearch = client .prepareSearch (indexName )
1087
+ .setQuery (QueryBuilders .idsQuery ().addIds (ForecastRequestStats .documentId (jobId , forecastId )));
1088
+
1089
+ searchSingleResult (jobId ,
1090
+ ForecastRequestStats .RESULTS_FIELD .getPreferredName (),
1091
+ forecastSearch ,
1092
+ ForecastRequestStats .LENIENT_PARSER ,result -> handler .accept (result .result ),
1093
+ errorHandler , () -> null );
1118
1094
}
1119
1095
1120
1096
public void getForecastStats (String jobId , Consumer <ForecastStats > handler , Consumer <Exception > errorHandler ) {
0 commit comments