Type to search.

Run a search with a search template

  • POST also GET /{index}/_search/template
  • POST also GET /_search/template
Auth The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability Generally available since 2.0 This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

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 (*).

Leave it out to use /_search/template.

Query parameters

allow_no_indices boolean · default: true

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

Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution.

expand_wildcards union oneOf · default: open

The type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as open,hidden.

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

If true, the response includes additional details about score computation as part of a hit.

ignore_throttled boolean · default: true deprecated

If true, specified concrete, expanded, or aliased indices are not included in the response when throttled.

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.

preference string

The node or shard the operation should be performed on. It is random by default.

profile boolean · default: false

If true, the query execution is profiled.

routing union string | string[]

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.

scroll union oneOf

Specifies how long a consistent view of the index should be maintained for scrolled search.

Values: -1 0
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 The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability Generally available since 7.0 This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

If true, hits.total is rendered as an integer in the response. If false, it is rendered as an object.

typed_keys boolean · default: false

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

Request body

explain boolean · default: false

If true, returns detailed information about score calculation as part of each hit. If you specify both this and the explain query parameter, the API uses only the query parameter.

id string

The ID of the search template to use. If no source is specified, this parameter is required.

params map string to object

Key-value pairs used to replace Mustache variables in the template. The key is the variable name. The value is the variable value.

profile boolean · default: false

If true, the query execution is profiled.

source union oneOf

An inline search template. Supports the same parameters as the search API's request body. It also supports Mustache variables. If no id is specified, this parameter is required.

One of:

Response

application/json
took number required
timed_out boolean required
_shards object required
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
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
_scroll_id string
suggest map string to oneOf
terminated_early boolean