Run a search with a search template
Generally available; Added in 2.0.0
Query parameters
-
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
. -
If
true
, network round-trips are minimized for cross-cluster search requests. -
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
. Valid values are:all
,open
,closed
,hidden
,none
.Values are
all
,open
,closed
,hidden
, ornone
. -
If
true
, the response includes additional details about score computation as part of a hit. -
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. -
The node or shard the operation should be performed on. It is random by default.
-
If
true
, the query execution is profiled. -
A custom value used to route operations to a specific shard.
-
Specifies how long a consistent view of the index should be maintained for scrolled search.
Values are
-1
or0
. -
The type of the search operation.
Values are
query_then_fetch
ordfs_query_then_fetch
. -
If
true
,hits.total
is rendered as an integer in the response. Iffalse
, it is rendered as an object. -
If
true
, the response prefixes aggregation and suggester names with their respective types.
Body
Required
-
If
true
, returns detailed information about score calculation as part of each hit. If you specify both this and theexplain
query parameter, the API uses only the query parameter. -
Key-value pairs used to replace Mustache variables in the template. The key is the variable name. The value is the variable value.
-
If
true
, the query execution is profiled. source
string | object One of: Hide attributes Show attributes
-
Defines the aggregations that are run as part of the search request.
External documentation -
External documentation -
If
true
, the request returns detailed information about score computation as part of a hit. -
Configuration of search extensions defined by Elasticsearch plugins.
-
The starting document offset, which must be non-negative. By default, you cannot page through more than 10,000 hits using the
from
andsize
parameters. To page through more hits, use thesearch_after
parameter. -
Hide highlight attributes Show highlight attributes object
-
A string that contains each boundary character.
-
How far to scan for boundary characters.
-
Values are
chars
,sentence
, orword
. -
Controls which locale is used to search for sentence and word boundaries. This parameter takes a form of a language tag, for example:
"en-US"
,"fr-FR"
,"ja-JP"
. -
Values are
simple
orspan
. -
The size of the highlighted fragment in characters.
-
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
External documentation -
If set to a non-negative value, highlighting stops at this defined maximum limit. The rest of the text is not processed, thus not highlighted and no error is returned The
max_analyzed_offset
query setting does not override theindex.highlight.max_analyzed_offset
setting, which prevails when it’s set to lower value than the query setting. -
The amount of text you want to return from the beginning of the field if there are no matching fragments to highlight.
-
The maximum number of fragments to return. If the number of fragments is set to
0
, no fragments are returned. Instead, the entire field contents are highlighted and returned. This can be handy when you need to highlight short texts such as a title or address, but fragmentation is not required. Ifnumber_of_fragments
is0
,fragment_size
is ignored. -
Value is
score
. -
Controls the number of matching phrases in a document that are considered. Prevents the
fvh
highlighter from analyzing too many phrases and consuming too much memory. When usingmatched_fields
,phrase_limit
phrases per matched field are considered. Raising the limit increases query time and consumes more memory. Only supported by thefvh
highlighter. -
Use in conjunction with
pre_tags
to define the HTML tags to use for the highlighted text. By default, highlighted text is wrapped in<em>
and</em>
tags. -
Use in conjunction with
post_tags
to define the HTML tags to use for the highlighted text. By default, highlighted text is wrapped in<em>
and</em>
tags. -
By default, only fields that contains a query match are highlighted. Set to
false
to highlight all fields. -
Value is
styled
. -
Values are
default
orhtml
.
-
Number of hits matching the query to count accurately. If true, the exact number of hits is returned at the cost of some performance. If false, the response does not include the total number of hits matching the query. Defaults to 10,000 hits.
-
Boost the
_score
of documents from specified indices. The boost value is the factor by which scores are multiplied. A boost value greater than1.0
increases the score. A boost value between0
and1.0
decreases the score.External documentation -
An array of wildcard (
*
) field patterns. The request returns doc values for field names matching these patterns in thehits.fields
property of the response.A reference to a field with formatting instructions on how to return the value
External documentation knn
object | array[object] The approximate kNN search to run.
One of: Hide attributes Show attributes
-
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
-
The final number of nearest neighbors to return as top hits
-
The number of nearest neighbor candidates to consider per shard
-
Boost value to apply to kNN scores
filter
object | array[object] Filters for the kNN search query
One of: An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
External documentation An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
-
The minimum similarity for a vector to be considered a match
-
Hide inner_hits attributes Show inner_hits attributes object
-
The maximum number of hits to return per
inner_hits
. -
Inner hit starting document offset.
-
External documentation -
A reference to a field with formatting instructions on how to return the value
A reference to a field with formatting instructions on how to return the value
-
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
External documentation Hide attributes Show attributes object
-
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
-
The final number of nearest neighbors to return as top hits
-
The number of nearest neighbor candidates to consider per shard
-
Boost value to apply to kNN scores
-
The minimum similarity for a vector to be considered a match
-
Hide inner_hits attributes Show inner_hits attributes object
-
The maximum number of hits to return per
inner_hits
. -
Inner hit starting document offset.
-
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
-
-
The minimum
_score
for matching documents. Documents with a lower_score
are not included in search results or results collected by aggregations. -
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
External documentation -
Set to
true
to return detailed timing information about the execution of individual components in a search request. NOTE: This is a debugging tool and adds significant overhead to search execution. -
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
External documentation rescore
object | array[object] Can be used to improve precision by reordering just the top (for example 100 - 500) documents returned by the
query
andpost_filter
phases.One of: Hide attributes Show attributes
-
Hide query attributes Show query attributes object
-
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
-
Relative importance of the original query versus the rescore query.
-
Relative importance of the rescore query versus the original query.
-
Values are
avg
,max
,min
,multiply
, ortotal
.
-
-
Hide retriever attributes Show retriever attributes object
-
Hide standard attributes Show standard attributes object
-
Minimum _score for matching documents. Documents with a lower _score are not included in the top documents.
-
Retriever name.
-
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
External documentation -
A field value.
-
Maximum number of documents to collect for each shard.
-
External documentation
-
Hide knn attributes Show knn attributes object
-
Minimum _score for matching documents. Documents with a lower _score are not included in the top documents.
-
Retriever name.
-
The name of the vector field to search against.
-
Number of nearest neighbors to return as top hits.
-
Number of nearest neighbor candidates to consider per shard.
-
The minimum similarity required for a document to be considered a match.
-
Hide rrf attributes Show rrf attributes object
-
Minimum _score for matching documents. Documents with a lower _score are not included in the top documents.
-
Retriever name.
-
A list of child retrievers to specify which sets of returned top documents will have the RRF formula applied to them.
-
This value determines how much influence documents in individual result sets per query have over the final ranked result set.
-
This value determines the size of the individual result sets per query.
-
Hide text_similarity_reranker attributes Show text_similarity_reranker attributes object
-
Minimum _score for matching documents. Documents with a lower _score are not included in the top documents.
-
Retriever name.
-
This value determines how many documents we will consider from the nested retriever.
-
Unique identifier of the inference endpoint created using the inference API.
-
The text snippet used as the basis for similarity comparison
-
The document field to be used for text similarity comparisons. This field should contain the text that will be evaluated against the inference_text
-
Hide rule attributes Show rule attributes object
-
Minimum _score for matching documents. Documents with a lower _score are not included in the top documents.
-
Retriever name.
-
The match criteria that will determine if a rule in the provided rulesets should be applied.
-
This value determines the size of the individual result set.
-
Hide rescorer attributes Show rescorer attributes object
-
Hide linear attributes Show linear attributes object
-
Minimum _score for matching documents. Documents with a lower _score are not included in the top documents.
-
Retriever name.
-
Inner retrievers.
-
Hide pinned attributes Show pinned attributes object
-
-
Retrieve a script evaluation (based on different fields) for each hit.
Hide script_fields attribute Show script_fields attribute object
-
Hide * attributes Show * attributes object
-
-
A field value.
-
The number of hits to return, which must not be negative. By default, you cannot page through more than 10,000 hits using the
from
andsize
parameters. To page through more hits, use thesearch_after
property. sort
string | object | array[string | object] One of: Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
Hide attributes Show attributes
-
Hide _geo_distance attributes Show _geo_distance attributes object
-
An array of wildcard (
*
) field patterns. The request returns values for field names matching these patterns in thehits.fields
property of the response.A reference to a field with formatting instructions on how to return the value
-
The maximum number of documents to collect for each shard. If a query reaches this limit, Elasticsearch terminates the query early. Elasticsearch collects documents before sorting.
IMPORTANT: Use with caution. Elasticsearch applies this property to each shard handling the request. When possible, let Elasticsearch perform early termination automatically. Avoid specifying this property for requests that target data streams with backing indices across multiple data tiers.
If set to
0
(default), the query does not terminate early. -
The period of time to wait for a response from each shard. If no response is received before the timeout expires, the request fails and returns an error. Defaults to no timeout.
-
If
true
, calculate and return document scores, even if the scores are not used for sorting. -
If
true
, the request returns the document version as part of a hit. -
If
true
, the request returns sequence number and primary term of the last modification of each hit.External documentation -
Hide runtime_mappings attribute Show runtime_mappings attribute object
-
Hide * attributes Show * attributes object
-
For type
composite
-
For type
lookup
-
A custom format for
date
type runtime fields. -
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
-
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
-
Hide script attributes Show script attributes object
-
Values are
boolean
,composite
,date
,double
,geo_point
,geo_shape
,ip
,keyword
,long
, orlookup
.
-
-
-
The stats groups to associate with the search. Each group maintains a statistics aggregation for its associated searches. You can retrieve these stats using the indices stats API.
-
Responses
-
Hide response attributes Show response attributes object
-
Hide _shards attributes Show _shards attributes object
-
Hide failures attributes Show failures attributes object
-
Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.
Hide reason attributes Show reason attributes object
-
The type of error
-
The server stack trace. Present only if the
error_trace=true
parameter was sent with the request. -
Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.
-
Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.
Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.
-
Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.
Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.
-
-
Hide _clusters attributes Show _clusters attributes object
-
Hide details attribute Show details attribute object
-
Hide * attributes Show * attributes object
-
Values are
running
,successful
,partial
,skipped
, orfailed
. -
Time unit for milliseconds
-
Hide failures attributes Show failures attributes object
-
-
-
Hide profile attribute Show profile attribute object
-
Hide shards attributes Show shards attributes object
-
Hide dfs attributes Show dfs attributes object
-
Hide statistics attributes Show statistics attributes object
-
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
-
-
-
Hide fetch attributes Show fetch attributes object
-
Time unit for nanoseconds
-
-
-
Hide suggest attribute Show suggest attribute object
GET my-index/_search/template
{
"id": "my-search-template",
"params": {
"query_string": "hello world",
"from": 0,
"size": 10
}
}
resp = client.search_template(
index="my-index",
id="my-search-template",
params={
"query_string": "hello world",
"from": 0,
"size": 10
},
)
const response = await client.searchTemplate({
index: "my-index",
id: "my-search-template",
params: {
query_string: "hello world",
from: 0,
size: 10,
},
});
response = client.search_template(
index: "my-index",
body: {
"id": "my-search-template",
"params": {
"query_string": "hello world",
"from": 0,
"size": 10
}
}
)
$resp = $client->searchTemplate([
"index" => "my-index",
"body" => [
"id" => "my-search-template",
"params" => [
"query_string" => "hello world",
"from" => 0,
"size" => 10,
],
],
]);
curl -X GET -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"id":"my-search-template","params":{"query_string":"hello world","from":0,"size":10}}' "$ELASTICSEARCH_URL/my-index/_search/template"
{
"id": "my-search-template",
"params": {
"query_string": "hello world",
"from": 0,
"size": 10
}
}