| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 | ////This file is included by high level rest client API documentation pageswhere the client method does not use a request object.For methods with requests, see execution.asciidoc////[id="{upid}-{api}-sync"]==== Synchronous executionWhen executing the +{api}+ API in the following manner, the client waitsfor the +{response}+ to be returned before continuing with code execution:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-execute]--------------------------------------------------Synchronous calls may throw an `IOException` in case of either failing toparse the REST response in the high-level REST client, the request times outor similar cases where there is no response coming back from the server.In cases where the server returns a `4xx` or `5xx` error code, the high-levelclient tries to parse the response body error details instead and then throwsa generic `ElasticsearchException` and adds the original `ResponseException` as asuppressed exception to it.[id="{upid}-{api}-async"]==== Asynchronous executionThe +{api}+ API can also be called in an asynchronous fashion so thatthe client can return directly. Users need to specify how the response orpotential failures will be handled by passing a listener to theasynchronous {api} method:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-execute-async]--------------------------------------------------<1> The `RequestOptions` and `ActionListener` to use when the execution    completesThe asynchronous method does not block and returns immediately. Once it iscompleted the `ActionListener` is called back using the `onResponse` methodif the execution successfully completed or using the `onFailure` method ifit failed. Failure scenarios and expected exceptions are the same as in thesynchronous execution case.A typical listener for +{api}+ looks like:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-execute-listener]--------------------------------------------------<1> Called when the execution is successfully completed.<2> Called when the +{api}+ call fails.
 |