0
0
Elasticsearchquery~5 mins

Async search for expensive queries in Elasticsearch

Choose your learning style9 modes available
Introduction

Async search lets you run big, slow searches without waiting. You can check results later when ready.

When searching large data that takes a long time to finish.
When you want to avoid blocking your app while waiting for search results.
When you want to get partial results quickly and continue fetching more later.
When running reports or analytics that need heavy queries.
When you want to save resources by not keeping connections open during long searches.
Syntax
Elasticsearch
POST /_async_search
{
  "query": {
    "match": { "field": "value" }
  }
}

Use POST to /_async_search with your query inside the body.

The response gives you an id to check status or get results later.

Examples
Start an async search that matches all documents.
Elasticsearch
POST /_async_search
{
  "query": {
    "match_all": {}
  }
}
Check the status of your async search using the id from the start response.
Elasticsearch
GET /_async_search/status/{id}
Get the results of your async search once it is done.
Elasticsearch
GET /_async_search/{id}
Sample Program

This example starts an async search for documents with "error" in the message field. It shows how to check status and get results later.

Elasticsearch
POST /_async_search
{
  "query": {
    "match": {
      "message": "error"
    }
  }
}

# Response example:
# {
#   "id": "r1A2B3C4D5E6F7G8H9I",
#   "is_running": true,
#   "response": null
# }

# Later, check status:
GET /_async_search/status/r1A2B3C4D5E6F7G8H9I

# When done, get results:
GET /_async_search/r1A2B3C4D5E6F7G8H9I
OutputSuccess
Important Notes

Async search helps avoid timeouts on long queries.

You can cancel an async search by sending a DELETE request to /_async_search/{id}.

Partial results can be returned if the search is still running.

Summary

Async search runs slow queries without blocking your app.

Use the returned id to check status or get results later.

It is useful for big data, reports, and avoiding timeouts.