Search template API
editSearch template API
editRuns a search with a search template.
GET my-index/_search/template { "id": "my-search-template", "params": { "query_string": "hello world", "from": 0, "size": 10 } }
Request
editGET <target>/_search/template
GET _search/template
POST <target>/_search/template
POST _search/template
Prerequisites
edit-
If the Elasticsearch security features are enabled, you must have the
read
index privilege for the target data stream, index, or alias. For cross-cluster search, see Cross cluster search and security.
Path parameters
edit-
<target>
-
(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 parameters
edit-
allow_no_indices
-
(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 targetingfoo*,bar*
returns an error if an index starts withfoo
but no index starts withbar
.Defaults to
true
. -
ccs_minimize_roundtrips
-
(Optional, Boolean) If
true
, network round-trips are minimized for cross-cluster search requests. Defaults totrue
. -
expand_wildcards
-
(Optional, string) 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. Supports comma-separated values, such as
open,hidden
. Valid values are:-
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
-
(Optional, Boolean) If
true
, the response includes additional details about score computation as part of a hit. Defaults tofalse
. -
ignore_throttled
-
(Optional, Boolean) If
true
, specified concrete, expanded, or aliased indices are not included in the response when throttled. Defaults totrue
. -
ignore_unavailable
-
(Optional, Boolean) If
false
, the request returns an error if it targets a missing or closed index. Defaults tofalse
. -
preference
- (Optional, string) Specifies the node or shard the operation should be performed on. Random by default.
-
rest_total_hits_as_int
-
(Optional, Boolean) If
true
, the response returnshits.total
as an integer. If false, it returnshits.total
as an object. Defaults tofalse
. -
routing
- (Optional, string) Custom value used to route operations to a specific shard.
-
scroll
- (Optional, time units) Specifies how long a consistent view of the index should be maintained for scrolled search.
-
search_type
-
(Optional, string) The type of the search operation. Available options:
-
query_then_fetch
-
dfs_query_then_fetch
-
-
typed_keys
-
(Optional, Boolean) If
true
, the response prefixes aggregation and suggester names with their respective types. Defaults tofalse
.
Request body
edit-
explain
-
(Optional, Boolean) If
true
, returns detailed information about score calculation as part of each hit. Defaults tofalse
.If you specify both this and the
explain
query parameter, the API uses only the query parameter.
-
id
-
(Required*, string) ID of the search template to use. If no
source
is specified, this parameter is required. -
params
- (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.
-
profile
-
(Optional, Boolean) If
true
, the query execution is profiled. Defaults tofalse
. -
source
-
(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.