Search templates

Search templates are very similar to stored procedures in the relational database. Commonly used queries can be defined as a template, and the applications using Elasticsearch can simply refer to the query by its ID. The template accepts parameters, which can be specified at the runtime. Search templates are stored on the server side and can be modified without changes to the client code. Templates are expressed using the Mustache template engine. For more information on mustache, please visit

Let's start by defining a template query to find all the products by their name. The query is as follows:

#Define Template POST _search/template/find_product_by_name {   "query" : { "match" ...

Get Learning Elasticsearch now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.