Type to search.

Run multiple templated searches

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

Run multiple templated searches with a single request. If you are providing a text file or text input to curl, use the --data-binary flag instead of -d to preserve newlines. For example:

Text
$ cat requests
{ "index": "my-index" }
{ "id": "my-search-template", "params": { "query_string": "hello world", "from": 0, "size": 10 }}
{ "index": "my-other-index" }
{ "id": "my-other-search-template", "params": { "query_type": "match_all" }}

$ curl -H "Content-Type: application/x-ndjson" -XGET localhost:9200/_msearch/template --data-binary "@requests"; echo
More about searching templates

Required privileges

Index privileges read

Path parameters

index union string | string[] optional

A comma-separated list of data streams, indices, and aliases to search. It supports wildcards (*). To search all data streams and indices, omit this parameter or use *.

Leave it out to use /_msearch/template.

Query parameters

ccs_minimize_roundtrips boolean · default: true

If true, network round-trips are minimized for cross-cluster search requests.

max_concurrent_searches number

The maximum number of concurrent searches the API can run.

search_type enum

The type of the search operation.

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

If true, the response returns hits.total as an integer. If false, it returns hits.total as an object.

typed_keys boolean · default: false

If true, the response prefixes aggregation and suggester names with their respective types.

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.

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
fields map string to object
highlight map string to string
inner_hits map string to object
matched_queries union oneOf
One of: string[] or string to number
_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
fields map string to object
max_score number
num_reduce_phases number
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