@@ -405,7 +405,11 @@ private static void mergeIndexResponses(
405405 * Under no circumstances are we to pass timeout errors originating from SubscribableListener as top-level errors.
406406 * Instead, they should always be passed through the response object, as part of "failures".
407407 */
408- if (failures .stream ().anyMatch (failure -> failure .getException () instanceof ElasticsearchTimeoutException )) {
408+ if (failures .stream ()
409+ .anyMatch (
410+ failure -> failure .getException () instanceof IllegalStateException ise
411+ && ise .getCause () instanceof ElasticsearchTimeoutException
412+ )) {
409413 listener .onResponse (new FieldCapabilitiesResponse (Collections .emptyList (), failures ));
410414 } else {
411415 // throw back the first exception
@@ -618,15 +622,24 @@ List<FieldCapabilitiesFailure> build(Set<String> successfulIndices) {
618622 for (Map .Entry <String , Exception > failure : failuresByIndex .entrySet ()) {
619623 String index = failure .getKey ();
620624 Exception e = failure .getValue ();
625+ /*
626+ * The listener we use to briefly try, and connect to a remote can throw an ElasticsearchTimeoutException
627+ * error if a remote cannot be reached. To make sure we correctly recognise this scenario via
628+ * ExceptionsHelper.isRemoteUnavailableException(), we wrap this error appropriately.
629+ */
630+ if (e instanceof ElasticsearchTimeoutException ete ) {
631+ e = new IllegalStateException ("Unable to open any connections" , ete );
632+ }
621633
622634 if (successfulIndices .contains (index ) == false ) {
623635 // we deduplicate exceptions on the underlying causes message and classname
624636 // we unwrap the cause to e.g. group RemoteTransportExceptions coming from different nodes if the cause is the same
625637 Throwable cause = ExceptionsHelper .unwrapCause (e );
626638 Tuple <String , String > groupingKey = new Tuple <>(cause .getMessage (), cause .getClass ().getName ());
639+ Exception ex = e ;
627640 indexFailures .compute (
628641 groupingKey ,
629- (k , v ) -> v == null ? new FieldCapabilitiesFailure (new String [] { index }, e ) : v .addIndex (index )
642+ (k , v ) -> v == null ? new FieldCapabilitiesFailure (new String [] { index }, ex ) : v .addIndex (index )
630643 );
631644 }
632645 }
0 commit comments