Search template APIedit

Runs a search with a search template.

GET my-index/_search/template
  "id": "my-search-template",
  "params": {
    "query_string": "hello world",
    "from": 0,
    "size": 10


GET <target>/_search/template

GET _search/template

POST <target>/_search/template

POST _search/template


Path parametersedit

(Optional, string) Comma-separated list of data streams, indices, and aliases to search. Supports wildcards (*). To search all data streams and indices, omit this parameter or use *.

Query parametersedit


(Optional, Boolean) If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targeting foo*,bar* returns an error if an index starts with foo but no index starts with bar.

Defaults to true.

(Optional, Boolean) If true, network round-trips are minimized for cross-cluster search requests. Defaults to true.

(Optional, string) 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. Valid values are:

Match any data stream or index, including hidden ones.
Match open, non-hidden indices. Also matches any non-hidden data stream.
Match closed, non-hidden indices. Also matches any non-hidden data stream. Data streams cannot be closed.
Match hidden data streams and hidden indices. Must be combined with open, closed, or both.
Wildcard patterns are not accepted.
(Optional, Boolean) If true, the response includes additional details about score computation as part of a hit. Defaults to false.
(Optional, Boolean) If true, specified concrete, expanded, or aliased indices are not included in the response when throttled. Defaults to true.
(Optional, Boolean) If false, the request returns an error if it targets a missing or closed index. Defaults to false.
(Optional, string) Specifies the node or shard the operation should be performed on. Random by default.
(Optional, Boolean) If true, the response returns as an integer. If false, it returns as an object. Defaults to false.
(Optional, string) Custom value used to route operations to a specific shard.
(Optional, time units) Specifies how long a consistent view of the index should be maintained for scrolled search.

(Optional, string) The type of the search operation. Available options:

  • query_then_fetch
  • dfs_query_then_fetch
(Optional, Boolean) If true, the response prefixes aggregation and suggester names with their respective types. Defaults to false.

Request bodyedit


(Optional, Boolean) If true, returns detailed information about score calculation as part of each hit. Defaults to false.

If you specify both this and the explain query parameter, the API uses only the query parameter.

(Required*, string) ID of the search template to use. If no source is specified, this parameter is required.
(Optional, object) Key-value pairs used to replace Mustache variables in the template. The key is the variable name. The value is the variable value.
(Optional, Boolean) If true, the query execution is profiled. Defaults to false.

(Required*, object) An inline search template. Supports the same parameters as the search API's request body. Also supports Mustache variables.

If no id is specified, this parameter is required.