| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 | [[esql-async-query-api]]== {esql} async query API++++<titleabbrev>{esql} async query API</titleabbrev>++++Runs an async {esql} search.The async query API lets you asynchronously execute a search request,monitor its progress, and retrieve results as they become available.Executing an <<esql,ES|QL ({es} query language)>> is commonly quite fast,however searches across large data sets or frozen data can take some time.To avoid long waits, run an async {esql} search.Searches initiated by this API may return search results or not. The`wait_for_completion_timeout` property determines how long to wait forthe search results. The default value is 1 second. If the results arenot available by this time, a search id is return which can be laterused to retrieve the results.Initiates an async search for an <<esql,ES|QL ({es} query language)>>query. The API accepts the same parameters and request body as the<<esql-query-api,query API>>.[source,console]----POST /_query/async{  "query": """    FROM library    | EVAL year = DATE_TRUNC(1 YEARS, release_date)    | STATS MAX(page_count) BY year    | SORT year    | LIMIT 5  """,  "wait_for_completion_timeout": "2s"}----// TEST[setup:library]If the results are not available within the timeout period, 2 seconds inthis case, the search returns no results but rather a response thatincludes: * A search ID * An `is_running` value of true, indicating the search is ongoingThe query continues to run in the background without blocking otherrequests.[source,console-result]----{  "id": "FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=",  "is_running": true}----// TEST[skip: no access to search ID - may return response values]To check the progress of an async search, use the <<get-async-esql-query-api,getasync ES|QL query API>> with the search ID. Specify how long you'd like forcomplete results in the `wait_for_completion_timeout` parameter.[source,console]----GET /_query/async/FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=?wait_for_completion_timeout=30s----// TEST[skip: no access to search ID - may return response values]If the response's `is_running` value is `false`, the async search hasfinished, and the results are returned.[source,console-result]----{  "id": "FmNJRUZ1YWZCU3dHY1BIOUhaenVSRkEaaXFlZ3h4c1RTWFNocDdnY2FSaERnUTozNDE=",  "is_running": false,  "columns": ...}----// TEST[skip: no access to search ID - may return response values]Use the <<delete-async-eqsl-query-api,delete async ES|QL query API>> todelete an async search before the `keep_alive` period ends. If the queryis still running, {es} cancels it.[source,console]----DELETE /_query/async/delete/FmdMX2pIang3UWhLRU5QS0lqdlppYncaMUpYQ05oSkpTc3kwZ21EdC1tbFJXQToxOTI=----// TEST[skip: no access to search ID]
 |