# Run a search with a search template **POST /{index}/_search/template** **All methods and paths for this operation:**
GET /_search/template
POST /_search/template
GET /{index}/_search/template
POST /{index}/_search/template
## Required authorization * Index privileges: `read` [More about searching templates](https://www.elastic.co/docs/solutions/search/search-templates) ## Servers - http://api.example.com: http://api.example.com () ## Authentication methods - Api key auth - Basic auth - Bearer auth ## Parameters ### Path parameters - **index** (string | array[string]) A comma-separated list of data streams, indices, and aliases to search. It supports wildcards (`*`). ### 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) Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution. - **expand_wildcards** (string | array[string]) 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. - **explain** (boolean) If `true`, the response includes additional details about score computation as part of a hit. - **ignore_throttled** (boolean) If `true`, specified concrete, expanded, or aliased indices are not included in the response when throttled. - **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. - **preference** (string) The node or shard the operation should be performed on. It is random by default. - **profile** (boolean) If `true`, the query execution is profiled. - **routing** (string | array[string]) A custom value used to route operations to a specific shard. - **scroll** (string) Specifies how long a consistent view of the index should be maintained for scrolled search. - **search_type** (string) 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. - **rest_total_hits_as_int** (boolean) If `true`, `hits.total` is rendered as an integer in the response. If `false`, it is rendered as an object. - **typed_keys** (boolean) If `true`, the response prefixes aggregation and suggester names with their respective types. ### Body: application/json (object) - **explain** (boolean) 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** (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) If `true`, the query execution is profiled. - **source** (string | object) 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. ## Responses ### 200 #### Body: application/json (object) - **took** (number) - **timed_out** (boolean) - **_shards** (object) - **hits** (object) - **aggregations** (object) - **_clusters** (object) - **fields** (object) - **max_score** (number) - **num_reduce_phases** (number) - **profile** (object) - **pit_id** (string) - **_scroll_id** (string) - **suggest** (object) - **terminated_early** (boolean) [Powered by Bump.sh](https://bump.sh)