Run a search with a search template
- POST also GET /{index}/_search/template
- POST also GET /_search/template
Path Parameters
-
indexIndexName | IndexNameoptional -
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_indicesboolean · default: true If
false, the request returns an error if any wildcard expression, index alias, or_allvalue 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 withfoobut no index starts withbar.-
ccs_minimize_roundtripsboolean · default: false If
true, network round-trips are minimized for cross-cluster search requests.-
expand_wildcardsstring ExpandWildcards · 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 withopen,closed, orboth.none: Wildcard expressions are not accepted.
-
Values:
allopenclosedhiddennone -
explainboolean · default: false If
true, the response includes additional details about score computation as part of a hit.-
ignore_throttledboolean · default: truedeprecated If
true, specified concrete, expanded, or aliased indices are not included in the response when throttled.If
false, the request returns an error if it targets a missing or closed index.-
preferencestring The node or shard the operation should be performed on. It is random by default.
-
profileboolean · default: false If
true, the query execution is profiled.-
routingstring Routing A custom value used to route operations to a specific shard.
-
scrollstring Duration Specifies how long a consistent view of the index should be maintained for scrolled search.
-
search_typeSearchType 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_fetchdfs_query_then_fetch -
rest_total_hits_as_intboolean · default: false If
true,hits.totalis rendered as an integer in the response. Iffalse, it is rendered as an object.-
typed_keysboolean · default: false If
true, the response prefixes aggregation and suggester names with their respective types.
Request
-
explainboolean · default: false -
If
true, returns detailed information about score calculation as part of each hit. If you specify both this and theexplainquery parameter, the API uses only the query parameter. -
idstring Id -
The ID of the search template to use. If no
sourceis specified, this parameter is required. -
paramsmap 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.
-
profileboolean · default: false -
If
true, the query execution is profiled. -
sourcestring -
An inline search template. Supports the same parameters as the search API's request body. It also supports Mustache variables. If no
idis specified, this parameter is required.
Response
-
tooknumberrequired -
timed_outbooleanrequired -
_shardsShardStatisticsrequired -
failednumber uintrequired -
The number of shards the operation or search attempted to run on but failed.
-
successfulnumber uintrequired -
The number of shards the operation or search succeeded on.
-
totalnumber uintrequired -
The number of shards the operation or search will run on overall.
-
failuresShardFailure -
indexstring IndexName -
nodestring -
reasonErrorCauserequired -
typestringrequired -
The type of error
-
reasonstringnullable -
A human-readable explanation of the error, in English.
-
stack_tracestring -
The server stack trace. Present only if the
error_trace=trueparameter was sent with the request. -
caused_byErrorCause -
root_causeErrorCause -
suppressedErrorCause -
shardnumber -
statusstring -
primaryboolean -
skippednumber uint -
hitsHitsMetadatarequired -
totaloneOf -
Total hit count information, present only if
track_total_hitswasn'tfalsein the search request. -
hitsHitrequired -
_indexstring IndexNamerequired -
_idstring Id -
_scorenumber | stringnullable -
_explanationExplanation -
descriptionstringrequired -
detailsExplanationDetailrequired -
descriptionstringrequired -
detailsExplanationDetail -
valuenumberrequired -
valuenumberrequired -
fieldsmap string to object -
highlightmap string to string -
inner_hitsmap string to InnerHitsResult -
<string>InnerHitsResult -
hitsHitsMetadatarequired -
matched_queriesoneOf -
_ignoredstring -
ignored_field_valuesmap string to FieldValue -
_shardstring -
_nodestring -
_routingstring -
_sourceobject -
_ranknumber -
_seq_nonumber SequenceNumber -
_primary_termnumber -
_versionnumber VersionNumber -
sortSortResults -
max_scorenumber | stringnullable -
aggregationsmap string to Aggregate -
_clustersClusterStatistics -
fieldsmap string to object -
max_scorenumber -
num_reduce_phasesnumber -
profileProfile -
shardsShardProfilerequired -
aggregationsAggregationProfilerequired -
breakdownAggregationBreakdownrequired -
build_aggregationnumberrequired -
build_aggregation_countnumberrequired -
build_leaf_collectornumberrequired -
build_leaf_collector_countnumberrequired -
collectnumberrequired -
collect_countnumberrequired -
initializenumberrequired -
initialize_countnumberrequired -
post_collectionnumber -
post_collection_countnumber -
reducenumberrequired -
reduce_countnumberrequired -
descriptionstringrequired -
time_in_nanosDurationValueUnitNanosrequired -
typestringrequired -
debugAggregationProfileDebug -
collection_strategystring -
total_bucketsnumber -
built_bucketsnumber -
result_strategystring -
has_filterboolean -
delegatestring -
delegate_debugAggregationProfileDebug -
chars_fetchednumber -
extract_countnumber -
extract_nsnumber -
values_fetchednumber -
collect_analyzed_nsnumber -
collect_analyzed_countnumber -
surviving_bucketsnumber -
ordinals_collectors_usednumber -
numeric_collectors_usednumber -
empty_collectors_usednumber -
deferred_aggregatorsstring -
segments_with_deleted_docsnumber -
filtersAggregationProfileDelegateDebugFilter -
results_from_metadatanumber -
querystring -
specialized_forstring -
segments_countednumber -
segments_collectednumber -
map_reducerstring -
brute_force_usednumber -
dynamic_pruning_attemptednumber -
dynamic_pruning_usednumber -
skipped_due_to_no_datanumber -
childrenAggregationProfile -
clusterstringrequired -
dfsDfsProfile -
statisticsDfsStatisticsProfile -
typestringrequired -
descriptionstringrequired -
timestring Duration -
time_in_nanosDurationValueUnitNanosrequired -
breakdownDfsStatisticsBreakdownrequired -
collection_statisticsnumberrequired -
collection_statistics_countnumberrequired -
create_weightnumberrequired -
create_weight_countnumberrequired -
rewritenumberrequired -
rewrite_countnumberrequired -
term_statisticsnumberrequired -
term_statistics_countnumberrequired -
debugmap string to object -
childrenDfsStatisticsProfile -
knnDfsKnnProfile -
vector_operations_countnumber -
queryKnnQueryProfileResultrequired -
typestringrequired -
descriptionstringrequired -
timestring Duration -
time_in_nanosDurationValueUnitNanosrequired -
breakdownKnnQueryProfileBreakdownrequired -
advancenumberrequired -
advance_countnumberrequired -
build_scorernumberrequired -
build_scorer_countnumberrequired -
compute_max_scorenumberrequired -
compute_max_score_countnumberrequired -
count_weightnumberrequired -
count_weight_countnumberrequired -
create_weightnumberrequired -
create_weight_countnumberrequired -
matchnumberrequired -
match_countnumberrequired -
next_docnumberrequired -
next_doc_countnumberrequired -
scorenumberrequired -
score_countnumberrequired -
set_min_competitive_scorenumberrequired -
set_min_competitive_score_countnumberrequired -
shallow_advancenumberrequired -
shallow_advance_countnumberrequired -
debugmap string to object -
childrenKnnQueryProfileResult -
rewrite_timenumberrequired -
fetchFetchProfile -
typestringrequired -
descriptionstringrequired -
time_in_nanosDurationValueUnitNanosrequired -
breakdownFetchProfileBreakdownrequired -
load_sourcenumber -
load_source_countnumber -
load_stored_fieldsnumber -
load_stored_fields_countnumber -
next_readernumber -
next_reader_countnumber -
process_countnumber -
processnumber -
debugFetchProfileDebug -
stored_fieldsstring -
fast_pathnumber -
childrenFetchProfile -
idstringrequired -
indexstring IndexNamerequired -
node_idstringrequired -
searchesSearchProfilerequired -
collectorCollectorrequired -
namestringrequired -
reasonstringrequired -
time_in_nanosDurationValueUnitNanosrequired -
childrenCollector -
queryQueryProfilerequired -
breakdownQueryBreakdownrequired -
advancenumberrequired -
advance_countnumberrequired -
build_scorernumberrequired -
build_scorer_countnumberrequired -
create_weightnumberrequired -
create_weight_countnumberrequired -
matchnumberrequired -
match_countnumberrequired -
shallow_advancenumberrequired -
shallow_advance_countnumberrequired -
next_docnumberrequired -
next_doc_countnumberrequired -
scorenumberrequired -
score_countnumberrequired -
compute_max_scorenumberrequired -
compute_max_score_countnumberrequired -
count_weightnumberrequired -
count_weight_countnumberrequired -
set_min_competitive_scorenumberrequired -
set_min_competitive_score_countnumberrequired -
descriptionstringrequired -
time_in_nanosDurationValueUnitNanosrequired -
typestringrequired -
childrenQueryProfile -
rewrite_timenumberrequired -
shard_idnumberrequired -
pit_idstring Id -
_scroll_idstring ScrollId -
suggestmap string to Suggest -
terminated_earlyboolean