Run an async search Added in 7.7.0
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
-
wait_for_completion_timeout string
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.
-
keep_on_completion boolean
If
true
, results are stored for later retrieval when the search completes within thewait_for_completion_timeout
. -
keep_alive string
Specifies how long the async search needs to be available. Ongoing async searches and any saved search results are deleted after this period.
-
allow_no_indices boolean
Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes
_all
string or when no indices have been specified) -
allow_partial_search_results boolean
Indicate if an error should be returned if there is a partial search failure or timeout
-
analyzer string
The analyzer to use for the query string
-
analyze_wildcard boolean
Specify whether wildcard and prefix queries should be analyzed (default: false)
-
batched_reduce_size number
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).
-
ccs_minimize_roundtrips boolean
The default value is the only supported value.
-
default_operator string
The default operator for query string query (AND or OR)
Values are
and
,AND
,or
, orOR
. -
df string
The field to use as default where no field prefix is given in the query string
-
docvalue_fields string | array[string]
A comma-separated list of fields to return as the docvalue representation of a field for each hit
-
expand_wildcards string | array[string]
Whether to expand wildcard expression to concrete indices that are open, closed or both.
-
explain boolean
Specify whether to return detailed information about score computation as part of a hit
-
ignore_throttled boolean
Whether specified concrete, expanded or aliased indices should be ignored when throttled
-
lenient boolean
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
-
preference string
Specify the node or shard the operation should be performed on (default: random)
-
pre_filter_shard_size number
The default value cannot be changed, which enforces the execution of a pre-filter roundtrip to retrieve statistics from each shard so that the ones that surely don’t hold any document matching the query get skipped.
-
request_cache boolean
Specify if request cache should be used for this request or not, defaults to true
-
routing string
A comma-separated list of specific routing values
-
scroll string
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
search_type string
Search operation type
Values are
query_then_fetch
ordfs_query_then_fetch
. -
stats array[string]
Specific 'tag' of the request for logging and statistical purposes
-
stored_fields string | array[string]
A comma-separated list of stored fields to return as part of a hit
-
suggest_field string
Specifies which field to use for suggestions.
-
suggest_mode string
Specify suggest mode
Values are
missing
,popular
, oralways
. -
suggest_size number
How many suggestions to return in response
-
suggest_text string
The source text for which the suggestions should be returned.
-
terminate_after number
The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.
-
timeout string
Explicit operation timeout
-
track_total_hits boolean | number
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.
-
track_scores boolean
Whether to calculate and return scores even if they are not used for sorting
-
typed_keys boolean
Specify whether aggregation and suggester names should be prefixed by their respective types in the response
-
rest_total_hits_as_int boolean
-
version boolean
Specify whether to return document version as part of a hit
-
_source boolean | string | array[string]
True or false to return the _source field or not, or a list of fields to return
-
_source_excludes string | array[string]
A list of fields to exclude from the returned _source field
-
_source_includes string | array[string]
A list of fields to extract and return from the _source field
-
seq_no_primary_term boolean
Specify whether to return sequence number and primary term of the last modification of each hit
-
q string
Query in the Lucene query string syntax
-
size number
Number of hits to return (default: 10)
-
from number
Starting offset (default: 0)
-
sort string | array[string]
A comma-separated list of
: pairs
Body
-
aggregations object
-
collapse object
Additional properties are allowed.
-
explain boolean
If true, returns detailed information about score computation as part of a hit.
-
ext object
Configuration of search extensions defined by Elasticsearch plugins.
-
from number
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.
-
highlight object
Additional properties are allowed.
-
track_total_hits boolean | number
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.
-
indices_boost array[object]
Boosts the _score of documents from specified indices.
-
docvalue_fields array[object]
Array of wildcard (*) patterns. The request returns doc values for field names matching these patterns in the hits.fields property of the response.
knn object | array[object]
Defines the approximate kNN search to run.
-
min_score number
Minimum _score for matching documents. Documents with a lower _score are not included in the search results.
-
post_filter object
Additional properties are allowed.
-
profile boolean
-
query object
Additional properties are allowed.
rescore object | array[object]
-
script_fields object
Retrieve a script evaluation (based on different fields) for each hit.
-
search_after array[number | string | boolean | null | object]
A field value.
One of: Additional properties are allowed.
-
size number
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.
-
slice object
Additional properties are allowed.
_source boolean | object
Defines how to fetch a source. Fetching can be disabled entirely, or the source can be filtered.
-
fields array[object]
Array of wildcard (*) patterns. The request returns values for field names matching these patterns in the hits.fields property of the response.
-
suggest object
Additional properties are allowed.
-
terminate_after number
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.
-
timeout string
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.
-
track_scores boolean
If true, calculate and return document scores, even if the scores are not used for sorting.
-
version boolean
If true, returns document version as part of a hit.
-
seq_no_primary_term boolean
If true, returns sequence number and primary term of the last modification of each hit. See Optimistic concurrency control.
-
stored_fields string | array[string]
-
pit object
Additional properties are allowed.
-
runtime_mappings object
-
stats array[string]
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.
curl \
-X POST http://api.example.com/{index}/_async_search \
-H "Content-Type: application/json" \
-d '"{\n \"sort\": [\n { \"date\": { \"order\": \"asc\" } }\n ],\n \"aggs\": {\n \"sale_date\": {\n \"date_histogram\": {\n \"field\": \"date\",\n \"calendar_interval\": \"1d\"\n }\n }\n }\n}"'
{
"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" : [ ]
}
}
}