mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
* Remove `es-test-dir` book-scoped variable * Remove `plugins-examples-dir` book-scoped variable * Remove `:dependencies-dir:` and `:xes-repo-dir:` book-scoped variables - In `index.asciidoc`, two variables (`:dependencies-dir:` and `:xes-repo-dir:`) were removed. - In `sql/index.asciidoc`, the `:sql-tests:` path was updated to fuller path - In `esql/index.asciidoc`, the `:esql-tests:` path was updated idem * Replace `es-repo-dir` with `es-ref-dir` * Move `:include-xpack: true` to few files that use it, remove from index.asciidoc
146 lines
3.7 KiB
Text
146 lines
3.7 KiB
Text
[[search-template-api]]
|
|
=== Search template API
|
|
++++
|
|
<titleabbrev>Search template</titleabbrev>
|
|
++++
|
|
|
|
Runs a search with a <<search-template,search template>>.
|
|
|
|
////
|
|
[source,console]
|
|
----
|
|
PUT _scripts/my-search-template
|
|
{
|
|
"script": {
|
|
"lang": "mustache",
|
|
"source": {
|
|
"query": {
|
|
"match": {
|
|
"message": "{{query_string}}"
|
|
}
|
|
},
|
|
"from": "{{from}}",
|
|
"size": "{{size}}"
|
|
},
|
|
"params": {
|
|
"query_string": "My query string"
|
|
}
|
|
}
|
|
}
|
|
|
|
PUT my-index/_doc/1?refresh
|
|
{
|
|
"message": "hello world"
|
|
}
|
|
----
|
|
// TESTSETUP
|
|
////
|
|
|
|
[source,console]
|
|
----
|
|
GET my-index/_search/template
|
|
{
|
|
"id": "my-search-template",
|
|
"params": {
|
|
"query_string": "hello world",
|
|
"from": 0,
|
|
"size": 10
|
|
}
|
|
}
|
|
----
|
|
|
|
[[search-template-api-request]]
|
|
==== {api-request-title}
|
|
|
|
`GET <target>/_search/template`
|
|
|
|
`GET _search/template`
|
|
|
|
`POST <target>/_search/template`
|
|
|
|
`POST _search/template`
|
|
|
|
[[search-template-api-prereqs]]
|
|
==== {api-prereq-title}
|
|
|
|
* If the {es} {security-features} are enabled, you must have the `read`
|
|
<<privileges-list-indices,index privilege>> for the target data stream, index,
|
|
or alias. For cross-cluster search, see <<remote-clusters>>.
|
|
|
|
[[search-template-api-path-params]]
|
|
==== {api-path-parms-title}
|
|
|
|
`<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 `*`.
|
|
|
|
[[search-template-api-query-params]]
|
|
==== {api-query-parms-title}
|
|
|
|
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
|
|
+
|
|
Defaults to `true`.
|
|
|
|
`ccs_minimize_roundtrips`::
|
|
(Optional, Boolean) If `true`, network round-trips are minimized for
|
|
cross-cluster search requests. Defaults to `true`.
|
|
|
|
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
|
|
|
|
`explain`::
|
|
(Optional, Boolean) If `true`, the response includes additional details about
|
|
score computation as part of a hit. Defaults to `false`.
|
|
|
|
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=ignore_throttled]
|
|
|
|
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
|
|
|
|
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=preference]
|
|
|
|
`rest_total_hits_as_int`::
|
|
(Optional, Boolean) If `true`, the response returns `hits.total` as an integer.
|
|
If false, it returns `hits.total` as an object. Defaults to `false`.
|
|
|
|
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=routing]
|
|
|
|
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=scroll]
|
|
|
|
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=search_type]
|
|
|
|
`typed_keys`::
|
|
(Optional, Boolean) If `true`, the response prefixes aggregation and suggester
|
|
names with their respective types. Defaults to `false`.
|
|
|
|
[[search-template-api-request-body]]
|
|
==== {api-request-body-title}
|
|
|
|
// tag::body-params[]
|
|
`explain`::
|
|
(Optional, Boolean) If `true`, returns detailed information about score
|
|
calculation as part of each hit. Defaults to `false`.
|
|
// end::body-params[]
|
|
+
|
|
If you specify both this and the `explain` query parameter, the API uses only
|
|
the query parameter.
|
|
|
|
// tag::body-params[]
|
|
`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 to
|
|
`false`.
|
|
|
|
`source`::
|
|
(Required*, object) An inline search template. Supports the same parameters as
|
|
the <<search-search,search API>>'s request body. Also supports
|
|
https://mustache.github.io/[Mustache] variables.
|
|
+
|
|
If no `id` is specified, this parameter is required.
|
|
// end::body-params[]
|