@@ -338,18 +338,10 @@ protected void doClose() {
338
338
public void executeDfsPhase (ShardSearchRequest request , boolean keepStatesInContext ,
339
339
SearchShardTask task , ActionListener <SearchPhaseResult > listener ) {
340
340
final IndexShard shard = getShard (request );
341
- rewriteAndFetchShardRequest (shard , request , new ActionListener <ShardSearchRequest >() {
342
- @ Override
343
- public void onResponse (ShardSearchRequest rewritten ) {
344
- // fork the execution in the search thread pool
345
- runAsync (getExecutor (shard ), () -> executeDfsPhase (request , task , keepStatesInContext ), listener );
346
- }
347
-
348
- @ Override
349
- public void onFailure (Exception exc ) {
350
- listener .onFailure (exc );
351
- }
352
- });
341
+ rewriteAndFetchShardRequest (shard , request , listener .delegateFailure ((l , rewritten ) -> {
342
+ // fork the execution in the search thread pool
343
+ runAsync (getExecutor (shard ), () -> executeDfsPhase (request , task , keepStatesInContext ), l );
344
+ }));
353
345
}
354
346
355
347
private DfsSearchResult executeDfsPhase (ShardSearchRequest request ,
@@ -385,34 +377,26 @@ public void executeQueryPhase(ShardSearchRequest request, boolean keepStatesInCo
385
377
assert request .canReturnNullResponseIfMatchNoDocs () == false || request .numberOfShards () > 1
386
378
: "empty responses require more than one shard" ;
387
379
final IndexShard shard = getShard (request );
388
- rewriteAndFetchShardRequest (shard , request , new ActionListener <ShardSearchRequest >() {
389
- @ Override
390
- public void onResponse (ShardSearchRequest orig ) {
391
- // check if we can shortcut the query phase entirely.
392
- if (orig .canReturnNullResponseIfMatchNoDocs ()) {
393
- assert orig .scroll () == null ;
394
- final CanMatchResponse canMatchResp ;
395
- try {
396
- ShardSearchRequest clone = new ShardSearchRequest (orig );
397
- canMatchResp = canMatch (clone , false );
398
- } catch (Exception exc ) {
399
- listener .onFailure (exc );
400
- return ;
401
- }
402
- if (canMatchResp .canMatch == false ) {
403
- listener .onResponse (QuerySearchResult .nullInstance ());
404
- return ;
405
- }
380
+ rewriteAndFetchShardRequest (shard , request , listener .delegateFailure ((l , orig ) -> {
381
+ // check if we can shortcut the query phase entirely.
382
+ if (orig .canReturnNullResponseIfMatchNoDocs ()) {
383
+ assert orig .scroll () == null ;
384
+ final CanMatchResponse canMatchResp ;
385
+ try {
386
+ ShardSearchRequest clone = new ShardSearchRequest (orig );
387
+ canMatchResp = canMatch (clone , false );
388
+ } catch (Exception exc ) {
389
+ l .onFailure (exc );
390
+ return ;
391
+ }
392
+ if (canMatchResp .canMatch == false ) {
393
+ l .onResponse (QuerySearchResult .nullInstance ());
394
+ return ;
406
395
}
407
- // fork the execution in the search thread pool
408
- runAsync (getExecutor (shard ), () -> executeQueryPhase (orig , task , keepStatesInContext ), listener );
409
- }
410
-
411
- @ Override
412
- public void onFailure (Exception exc ) {
413
- listener .onFailure (exc );
414
396
}
415
- });
397
+ // fork the execution in the search thread pool
398
+ runAsync (getExecutor (shard ), () -> executeQueryPhase (orig , task , keepStatesInContext ), l );
399
+ }));
416
400
}
417
401
418
402
private IndexShard getShard (ShardSearchRequest request ) {
0 commit comments