Run multiple searches

  • POST also GET /{index}/_msearch
  • POST also GET /_msearch
Auth

The format of the request is similar to the bulk API format and makes use of the newline delimited JSON (NDJSON) format. The structure is as follows:

header\n
body\n
header\n
body\n
		

This structure is specifically optimized to reduce parsing if a specific search ends up redirected to another node.

Important

The final line of data must end with a newline character \n. Each newline character may be preceded by a carriage return \r. When sending requests to this endpoint the Content-Type header should be set to application/x-ndjson.

Required authorization

Index privileges read

Path parameters

index union string | string[] optional

Comma-separated list of data streams, indices, and index aliases to search.

Leave it out to use /_msearch.

Query parameters

allow_no_indices boolean

A setting that does two separate checks on the index expression. If false, the request returns an error (1) if any wildcard expression (including _all and *) resolves to zero matching indices or (2) if the complete set of resolved indices, aliases or data streams is empty after all expressions are evaluated. If true, index expressions that resolve to no indices are allowed and the request returns an empty result.

ccs_minimize_roundtrips boolean · default: true

If true, network roundtrips between the coordinating node and remote clusters are minimized for cross-cluster search requests.

expand_wildcards union oneOf · default: open

Type of index that wildcard expressions can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams.

Supported values include:

  • all: Match any data stream or index, including hidden ones.
  • open: Match open, non-hidden indices. Also matches any non-hidden data stream.
  • closed: Match closed, non-hidden indices. Also matches any non-hidden data stream. Data streams cannot be closed.
  • hidden: Match hidden data streams and hidden indices. Must be combined with open, closed, or both.
  • none: Wildcard expressions are not accepted.
Values: all open closed hidden none
ignore_throttled boolean · default: false deprecated

If true, concrete, expanded or aliased indices are ignored when frozen.

ignore_unavailable boolean · default: false

If false, the request returns an error if it targets a concrete (non-wildcarded) index, alias, or data stream that is missing, closed, or otherwise unavailable. If true, unavailable concrete targets are silently ignored.

include_named_queries_score boolean · default: false

Indicates whether hit.matched_queries should be rendered as a map that includes the name of the matched query associated with its score (true) or as an array containing the name of the matched queries (false) This functionality reruns each named query on every hit in a search response. Typically, this adds a small overhead to a request. However, using computationally expensive named queries on a large number of hits may add significant overhead.

index union string | string[]

Comma-separated list of data streams, indices, and index aliases to use as default

max_concurrent_searches number

Maximum number of concurrent searches the multi search API can execute. Defaults to max(1, (# of data nodes * min(search thread pool size, 10))).

max_concurrent_shard_requests number · default: 5

Maximum number of concurrent shard requests that each sub-search request executes per node.

pre_filter_shard_size number

Defines a threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on its rewrite method i.e., if date filters are mandatory to match but the shard bounds and the query are disjoint.

rest_total_hits_as_int boolean · default: false

If true, hits.total are returned as an integer in the response. Defaults to false, which returns an object.

routing union string | string[]

Custom routing value used to route search operations to a specific shard. Not allowed when index.slice.enabled is true for the target index; use _slice instead.

search_type enum

Indicates whether global term and document frequencies should be used when scoring returned documents.

Supported values include:

  • query_then_fetch: Documents are scored using local term and document frequencies for the shard. This is usually faster but less accurate.
  • dfs_query_then_fetch: Documents are scored using global term and document frequencies across all shards. This is usually slower but more accurate.
Values: query_then_fetch dfs_query_then_fetch
typed_keys boolean

Specifies whether aggregation and suggester names should be prefixed by their respective types in the response.

Request body

An array; each item is one of:

Contains parameters used to limit or change the subsequent search body request.

allow_no_indices boolean

A setting that does two separate checks on the index expression. If false, the request returns an error (1) if any wildcard expression (including _all and *) resolves to zero matching indices or (2) if the complete set of resolved indices, aliases or data streams is empty after all expressions are evaluated. If true, index expressions that resolve to no indices are allowed and the request returns an empty result.

expand_wildcards union oneOf

Supported values include:

  • all: Match any data stream or index, including hidden ones.
  • open: Match open, non-hidden indices. Also matches any non-hidden data stream.
  • closed: Match closed, non-hidden indices. Also matches any non-hidden data stream. Data streams cannot be closed.
  • hidden: Match hidden data streams and hidden indices. Must be combined with open, closed, or both.
  • none: Wildcard expressions are not accepted.
Values: all open closed hidden none
ignore_unavailable boolean

If false, the request returns an error if it targets a concrete (non-wildcarded) index, alias, or data stream that is missing, closed, or otherwise unavailable. If true, unavailable concrete targets are silently ignored.

index union oneOf
One of: string[] or string
preference string
project_routing string
request_cache boolean
routing union oneOf

A custom value used to route operations to a specific shard. Not allowed when index.slice.enabled is true for the target index; use _slice instead.

One of: string[] or string
search_type enum

Supported values include:

  • query_then_fetch: Documents are scored using local term and document frequencies for the shard. This is usually faster but less accurate.
  • dfs_query_then_fetch: Documents are scored using global term and document frequencies across all shards. This is usually slower but more accurate.
Values: query_then_fetch dfs_query_then_fetch
ccs_minimize_roundtrips boolean
allow_partial_search_results boolean
ignore_throttled boolean

Response

application/json
took number required
responses union oneOf[] required
One of:
took number required

The number of milliseconds it took Elasticsearch to run the request. This value is calculated by measuring the time elapsed between receipt of a request on the coordinating node and the time at which the coordinating node is ready to send the response. It includes:

  • Communication time between the coordinating node and data nodes
  • Time the request spends in the search thread pool, queued for execution
  • Actual run time

It does not include:

  • Time needed to send the request to Elasticsearch
  • Time needed to serialize the JSON response
  • Time needed to send the response to a client
timed_out boolean required

If true, the request timed out before completion; returned results may be partial or empty.

_shards object required

A count of shards used for the request.

failed number required

The number of shards the operation or search attempted to run on but failed.

successful number required

The number of shards the operation or search succeeded on.

total number required

The number of shards the operation or search will run on overall.

failures object[]
index string
node string
reason object required
type string required

The type of error

reason union string nullable

A human-readable explanation of the error, in English.

One of: string
stack_trace string

The server stack trace. Present only if the error_trace=true parameter was sent with the request.

caused_by object
Same fields as reason in failures
root_cause object[]
Same fields as reason in failures
suppressed object[]
Same fields as reason in failures
shard number
status string
primary boolean
skipped number
hits object required

The returned documents and metadata.

total union oneOf

Total hit count information, present only if track_total_hits wasn't false in the search request.

One of:
relation enum required

Supported values include:

  • eq: Accurate
  • gte: Lower bound, including returned events or sequences
Values: eq gte
value number required
hits object[] required
_index string required
_id string
_score union number | string nullable
_explanation object
description string required
details object[] required
description string required
details object[]
Same fields as details in _explanation
value number required
value number required
fields map string to object
highlight map string to string
inner_hits map string to object
<string> object
hits object required
Same fields as hits in MultiSearchItem
matched_queries union oneOf
One of: string[] or string to number
_nested object
field string required
offset number required
_nested object
Same fields as _nested in hits
_ignored string[]
ignored_field_values map string to object
_shard string
_node string
_routing string
_source object
_rank number
_seq_no number
_primary_term number
_version number
sort union[]
max_score union number | string nullable
aggregations map string to {} Aggregation result
_clusters object
skipped number required
successful number required
total number required
running number required
partial number required
failed number required
details map string to object
<string> object
status enum required
Values: running successful partial skipped failed
indices string required
took number
timed_out boolean required
_shards object
Same fields as _shards in MultiSearchItem
failures object[]
Same fields as failures in _shards
fields map string to object
max_score number
num_reduce_phases number
profile object
shards object[] required
aggregations object[] required
breakdown object required
build_aggregation number required
build_aggregation_count number required
build_leaf_collector number required
build_leaf_collector_count number required
collect number required
collect_count number required
initialize number required
initialize_count number required
post_collection number
post_collection_count number
reduce number required
reduce_count number required
description string required
time_in_nanos number required
type string required
debug object
segments_with_multi_valued_ords number
collection_strategy string
segments_with_single_valued_ords number
total_buckets number
built_buckets number
result_strategy string
has_filter boolean
delegate string
delegate_debug object
Same fields as debug in aggregations
chars_fetched number
extract_count number
extract_ns number
values_fetched number
collect_analyzed_ns number
collect_analyzed_count number
surviving_buckets number
ordinals_collectors_used number
ordinals_collectors_overhead_too_high number
string_hashing_collectors_used number
numeric_collectors_used number
empty_collectors_used number
deferred_aggregators string[]
segments_with_doc_count_field number
segments_with_deleted_docs number
filters object[]
results_from_metadata number
query string
specialized_for string
segments_counted_in_constant_time number
segments_counted number
segments_collected number
map_reducer string
brute_force_used number
dynamic_pruning_attempted number
dynamic_pruning_used number
skipped_due_to_no_data number
children object[]
Same fields as aggregations in shards
cluster string required
dfs object
statistics object
type string required
description string required
time string
time_in_nanos number required
breakdown object required
collection_statistics number required
collection_statistics_count number required
create_weight number required
create_weight_count number required
rewrite number required
rewrite_count number required
term_statistics number required
term_statistics_count number required
debug map string to object
children object[]
Same fields as statistics in dfs
knn object[]
vector_operations_count number
query object[] required
type string required
description string required
time string
time_in_nanos number required
breakdown object required
advance number required
advance_count number required
build_scorer number required
build_scorer_count number required
compute_max_score number required
compute_max_score_count number required
count_weight number required
count_weight_count number required
create_weight number required
create_weight_count number required
match number required
match_count number required
next_doc number required
next_doc_count number required
score number required
score_count number required
set_min_competitive_score number required
set_min_competitive_score_count number required
shallow_advance number required
shallow_advance_count number required
debug map string to object
children object[]
Same fields as query in knn
rewrite_time number required
collector object[] required
name string required
reason string required
time string
time_in_nanos number required
children object[]
Same fields as collector in knn
fetch object
type string required
description string required
time_in_nanos number required
breakdown object required
load_source number
load_source_count number
load_stored_fields number
load_stored_fields_count number
next_reader number
next_reader_count number
process_count number
process number
debug object
stored_fields string[]
fast_path number
children object[]
Same fields as fetch in shards
id string required
index string required
node_id string required
rescore union oneOf[]

One entry per rescorer, in the order they ran. Omitted when the request has no rescorer.

One of:
type enum required
Values: query
description string required

What the rescorer runs.

time_in_nanos number required

The total time spent in the rescorer, including the time spent running its queries.

time string

The time spent in the rescorer, in human-readable units. Only returned when human is true.

debug map string to object

Extra details about the rescorer.

Every rescorer reports window_size, the number of top documents it was configured to rescore. timed_out is set to true if the search timed out while the rescorer was running. Rescorers can add their own keys.

breakdown object required

The query rescorer does not report any steps.

searches object[] required
collector object[] required
name string required
reason string required
time_in_nanos number required
children object[]
Same fields as collector in searches
query object[] required
breakdown object required
advance number required
advance_count number required
build_scorer number required
build_scorer_count number required
create_weight number required
create_weight_count number required
match number required
match_count number required
shallow_advance number required
shallow_advance_count number required
next_doc number required
next_doc_count number required
score number required
score_count number required
compute_max_score number required
compute_max_score_count number required
count_weight number required
count_weight_count number required
set_min_competitive_score number required
set_min_competitive_score_count number required
description string required
time_in_nanos number required
type string required
debug map string to object

Extra details about the query.

Queries run by a rescorer include a rescorer key with the position of that rescorer in the shard's rescore array.

children object[]
Same fields as query in searches
rewrite_time number required
shard_id number required
request object

When profiling is enabled, the original query source and target indices from the coordinating request.

source object

Original query source from the search request (SearchSourceBuilder as JSON).

aggregations map string to {} Aggregation

Defines the aggregations that are run as part of the search request.

collapse object

Collapses search results the values of the specified field.

Same fields as collapse in SearchRequestBody
explain boolean · default: false

If true, the request returns detailed information about score computation as part of a hit.

ext map string to object

Configuration of search extensions defined by Elasticsearch plugins.

from number · default: 0

The starting document offset, which must be non-negative. 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

Specifies the highlighter to use for retrieving highlighted snippets from one or more fields in your search results.

Same fields as highlight in inner_hits
track_total_hits boolean | number · default: 10000

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.

indices_boost string to number[]

Boost the _score of documents from specified indices. The boost value is the factor by which scores are multiplied. A boost value greater than 1.0 increases the score. A boost value between 0 and 1.0 decreases the score.

docvalue_fields object[]

An array of wildcard (*) field patterns. The request returns doc values for field names matching these patterns in the hits.fields property of the response.

field string required

A wildcard pattern. The request returns values for field names matching this pattern.

format string

The format in which the values are returned.

include_unmapped boolean
knn union oneOf

The approximate kNN search to run.

object or object[]
Same options as knn in SearchRequestBody
rank object

The Reciprocal Rank Fusion (RRF) to use.

rrf object

The reciprocal rank fusion parameters

rank_constant number

How much influence documents in individual result sets per query have over the final ranked result set

rank_window_size number

Size of the individual result sets per query

min_score number

The minimum _score for matching documents. Documents with a lower _score are not included in search results or results collected by aggregations.

post_filter {} Query

Use the post_filter parameter to filter search results. The search hits are filtered after the aggregations are calculated. A post filter has no impact on the aggregation results.

profile boolean · default: false

Set to true to return detailed timing information about the execution of individual components in a search request. NOTE: This is a debugging tool and adds significant overhead to search execution.

query {} Query

The search definition using the Query DSL.

rescore union oneOf

Can be used to improve precision by reordering just the top (for example 100 - 500) documents returned by the query and post_filter phases.

object or object[]
Same options as rescore in SearchRequestBody
retriever object

A retriever is a specification to describe top documents returned from a search. A retriever replaces other elements of the search API that also return top documents such as query and knn.

Same fields as retriever in SearchRequestBody
script_fields map string to object

Retrieve a script evaluation (based on different fields) for each hit.

<string> object
script string required
ignore_failure boolean
search_after union[]

Used to retrieve the next page of hits using a set of sort values from the previous page.

size number · default: 10

The number of hits to return, which must not be negative. 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 property.

slice object

Split a scrolled search into multiple slices that can be consumed independently.

field string
id string required
max number required
sort union oneOf

A comma-separated list of

Same options as sort in inner_hits
_source union oneOf

The source fields that are returned for matching documents. These fields are returned in the hits._source property of the search response. If the stored_fields property is specified, the _source property defaults to false. Otherwise, it defaults to true.

One of:
fields object[]

An array of wildcard (*) field patterns. The request returns values for field names matching these patterns in the hits.fields property of the response.

field string required

A wildcard pattern. The request returns values for field names matching this pattern.

format string

The format in which the values are returned.

include_unmapped boolean
suggest object

Defines a suggester that provides similar looking terms based on a provided text.

text string

Global suggest text, to avoid repetition when the same text is used in several suggesters

terminate_after number · default: 0

The 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.

Important

Use with caution. Elasticsearch applies this property to each shard handling the request. When possible, let Elasticsearch perform early termination automatically. Avoid specifying this property for requests that target data streams with backing indices across multiple data tiers.

If set to 0 (default), the query does not terminate early.

timeout string

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 · default: false

If true, calculate and return document scores, even if the scores are not used for sorting.

version boolean · default: false

If true, the request returns the document version as part of a hit.

seq_no_primary_term boolean

If true, the request returns sequence number and primary term of the last modification of each hit.

stored_fields union oneOf

A comma-separated list of stored fields to return as part of a hit. If no fields are specified, no stored fields are included in the response. If this field is specified, the _source property defaults to false. You can pass _source: true to return both source fields and stored fields in the search response.

One of: string[] or string
pit object

Limit the search to a point in time (PIT). If you provide a PIT, you cannot specify an <index> in the request path.

id string required
keep_alive string
runtime_mappings object

One or more runtime fields in the search request. These fields take precedence over mapped fields with the same name.

stats string[]

The 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.

indices string[]

Target index expressions from the request (before index resolution).

pit_id string

An updated identifier for the point-in-time that was searched.

Important

Each search request against a PIT returns in its response a pit_id field which may be different from the identifier you originally supplied. Always use the most recently-received PIT identifier for the next request. If you make concurrent search requests against the same PIT, Elasticsearch can return several different pit_id values in its responses. In that case, use any of these values for later requests, preferring more recently-received values whenever possible.

_scroll_id string

The identifier for the search and its search context. You can use this scroll ID with the scroll API to retrieve the next batch of search results for the request. This property is returned only if the scroll query parameter is specified in the request.

suggest map string to oneOf
terminated_early boolean
status number