Using search templates to pre-render search requests
Search templates are a way to define templates for search queries. These templates act as placeholders for variables defined inside the search queries. You can store search templates as Mustache scripts in the cluster state or provide them inline in the request body.
In this recipe, we will show you how to create and use search templates in Elasticsearch and explain how they work behind the scenes. We will also explore some of the benefits and use cases of search templates.
Getting ready
To follow along in this recipe, you’ll need an Elastic deployment up and running with Elasticsearch and Kibana. To spin up a cluster on Elastic Cloud refer to the Installing Elastic Stack with Elastic Cloud on Kubernetes recipe in Chapter 1.
Also, you’ll need the sample movie dataset we’ve previously used in the Indexing multiple documents using Bulk API recipe in Chapter 2.
The code used in this recipe is available...