Run an async search
Generally available
When the primary sort of the results is an indexed field, shards get sorted based on minimum and maximum value that they hold for that field. Partial results become available following the sort criteria that was requested.
Warning: Asynchronous search does not support scroll or search requests that include only the suggest section.
By default, Elasticsearch does not allow you to store an async search response larger than 10Mb and an attempt to do this results in an error.
The maximum allowed size for a stored async search response can be set by changing the search.max_async_search_response_size
cluster level setting.
Path parameters
-
A comma-separated list of index names to search; use
_all
or empty string to perform the operation on all indices
Query parameters
-
Blocks and waits until the search is completed up to a certain timeout. When the async search completes within the timeout, the response won’t include the ID as the results are not stored in the cluster.
Values are
-1
or0
. -
Specifies how long the async search needs to be available. Ongoing async searches and any saved search results are deleted after this period.
Values are
-1
or0
. -
If
true
, results are stored for later retrieval when the search completes within thewait_for_completion_timeout
. -
Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes
_all
string or when no indices have been specified) -
Indicate if an error should be returned if there is a partial search failure or timeout
-
The analyzer to use for the query string
-
Specify whether wildcard and prefix queries should be analyzed (default: false)
-
Affects how often partial results become available, which happens whenever shard results are reduced. A partial reduction is performed every time the coordinating node has received a certain number of new shard responses (5 by default).
-
The default value is the only supported value.
-
The default operator for query string query (AND or OR)
Values are
and
,AND
,or
, orOR
. -
The field to use as default where no field prefix is given in the query string
-
A comma-separated list of fields to return as the docvalue representation of a field for each hit
-
Whether to expand wildcard expression to concrete indices that are open, closed or both.
Values are
all
,open
,closed
,hidden
, ornone
. -
Specify whether to return detailed information about score computation as part of a hit
-
Whether specified concrete, expanded or aliased indices should be ignored when throttled
-
Specify whether format-based query failures (such as providing text to a numeric field) should be ignored
-
The number of concurrent shard requests per node this search executes concurrently. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests
-
Specify the node or shard the operation should be performed on (default: random)
-
Specify if request cache should be used for this request or not, defaults to true
-
A comma-separated list of specific routing values
-
Search operation type
Values are
query_then_fetch
ordfs_query_then_fetch
. -
Specific 'tag' of the request for logging and statistical purposes
-
A comma-separated list of stored fields to return as part of a hit
-
Specifies which field to use for suggestions.
-
Specify suggest mode
Values are
missing
,popular
, oralways
. -
How many suggestions to return in response
-
The source text for which the suggestions should be returned.
-
The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.
-
Explicit operation timeout
Values are
-1
or0
. -
Indicate if the number of documents that match the query should be tracked. A number can also be specified, to accurately track the total hit count up to the number.
-
Whether to calculate and return scores even if they are not used for sorting
-
Specify whether aggregation and suggester names should be prefixed by their respective types in the response
-
Indicates whether hits.total should be rendered as an integer or an object in the rest search response
-
Specify whether to return document version as part of a hit
-
True or false to return the _source field or not, or a list of fields to return
-
A list of fields to exclude from the returned _source field
-
A list of fields to extract and return from the _source field
-
Specify whether to return sequence number and primary term of the last modification of each hit
-
Query in the Lucene query string syntax
-
Number of hits to return (default: 10)
-
Starting offset (default: 0)
-
A comma-separated list of : pairs
Body
-
External documentation -
If true, returns detailed information about score computation as part of a hit.
-
Configuration of search extensions defined by Elasticsearch plugins.
-
Starting document offset. By default, you cannot page through more than 10,000 hits using the from and size parameters. To page through more hits, use the search_after parameter.
-
Number of hits matching the query to count accurately. If true, the exact number of hits is returned at the cost of some performance. If false, the response does not include the total number of hits matching the query. Defaults to 10,000 hits.
-
Boosts the _score of documents from specified indices.
-
Array of wildcard (*) patterns. The request returns doc values for field names matching these patterns in the hits.fields property of the response.
A reference to a field with formatting instructions on how to return the value
-
Minimum _score for matching documents. Documents with a lower _score are not included in search results and results collected by aggregations.
-
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
External documentation -
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
External documentation -
Retrieve a script evaluation (based on different fields) for each hit.
-
A field value.
-
The number of hits to return. By default, you cannot page through more than 10,000 hits using the from and size parameters. To page through more hits, use the search_after parameter.
-
Array of wildcard (*) patterns. The request returns values for field names matching these patterns in the hits.fields property of the response.
A reference to a field with formatting instructions on how to return the value
-
Maximum number of documents to collect for each shard. If a query reaches this limit, Elasticsearch terminates the query early. Elasticsearch collects documents before sorting. Defaults to 0, which does not terminate query execution early.
-
Specifies the period of time to wait for a response from each shard. If no response is received before the timeout expires, the request fails and returns an error. Defaults to no timeout.
-
If true, calculate and return document scores, even if the scores are not used for sorting.
-
If true, returns document version as part of a hit.
-
If true, returns sequence number and primary term of the last modification of each hit. See Optimistic concurrency control.
-
Stats groups to associate with the search. Each group maintains a statistics aggregation for its associated searches. You can retrieve these stats using the indices stats API.
POST /sales*/_async_search?size=0
{
"sort": [
{ "date": { "order": "asc" } }
],
"aggs": {
"sale_date": {
"date_histogram": {
"field": "date",
"calendar_interval": "1d"
}
}
}
}
resp = client.async_search.submit(
index="sales*",
size="0",
sort=[
{
"date": {
"order": "asc"
}
}
],
aggs={
"sale_date": {
"date_histogram": {
"field": "date",
"calendar_interval": "1d"
}
}
},
)
const response = await client.asyncSearch.submit({
index: "sales*",
size: 0,
sort: [
{
date: {
order: "asc",
},
},
],
aggs: {
sale_date: {
date_histogram: {
field: "date",
calendar_interval: "1d",
},
},
},
});
response = client.async_search.submit(
index: "sales*",
size: "0",
body: {
"sort": [
{
"date": {
"order": "asc"
}
}
],
"aggs": {
"sale_date": {
"date_histogram": {
"field": "date",
"calendar_interval": "1d"
}
}
}
}
)
$resp = $client->asyncSearch()->submit([
"index" => "sales*",
"size" => "0",
"body" => [
"sort" => array(
[
"date" => [
"order" => "asc",
],
],
),
"aggs" => [
"sale_date" => [
"date_histogram" => [
"field" => "date",
"calendar_interval" => "1d",
],
],
],
],
]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"sort":[{"date":{"order":"asc"}}],"aggs":{"sale_date":{"date_histogram":{"field":"date","calendar_interval":"1d"}}}}' "$ELASTICSEARCH_URL/sales*/_async_search?size=0"
{
"sort": [
{ "date": { "order": "asc" } }
],
"aggs": {
"sale_date": {
"date_histogram": {
"field": "date",
"calendar_interval": "1d"
}
}
}
}
{
"id" : "FmRldE8zREVEUzA2ZVpUeGs2ejJFUFEaMkZ5QTVrSTZSaVN3WlNFVmtlWHJsdzoxMDc=",
"is_partial" : true,
"is_running" : true,
"start_time_in_millis" : 1583945890986,
"expiration_time_in_millis" : 1584377890986,
"response" : {
"took" : 1122,
"timed_out" : false,
"num_reduce_phases" : 0,
"_shards" : {
"total" : 562,
"successful" : 3,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 157483,
"relation" : "gte"
},
"max_score" : null,
"hits" : [ ]
}
}
}