Using Search Templates in Elasticsearch 7.13

2 hours
  • 3 Learning Objectives

About this Hands-on Lab

Search templates in Elasticsearch allow you to parametrize a stored search so it can be repeatedly executed with variables. In this hands-on lab, you will get to create and use search templates in Elasticsearch.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the flights_template Search Template

From the Kibana console, create the flights_template search template as follows:

  • Paginate the search results with a default page size of 25 and displays the first page by default.
  • Perform a case-insensitive search on the Carrier field with the carrier parameter and is defaulted to search for all carriers.
  • Perform a case-insensitive search on the OriginCityName field with the origin parameter and is defaulted to search for all origin cities.
  • Perform a case-insensitive search on the DestCityName field with the destination parameter and is defaulted to search for all destination cities.
  • Sort the results by the AvgTicketPrice in descending order.
Render the flights_template Search Template without Any Parameters

From the Kibana console, render the flights_template search template without any parameters to test the query structure and default values.

Use the flights_template Search Template

From the Kibana console, use the flights_template search template with some sample searches. For example, try searching for flights by "Logstash Airways" from "Berlin" to "New York" with a results size of 10 per page.

Additional Resources

You work as a software engineer for an airline company who is developing a new flights search feature. You have a sample dataset of some flights stored in your non-production Elasticsearch cluster and need to develop the following search template: flights_template.

  • Paginate the search results with a default page size of 25 and displays the first page by default.
  • Perform a case-insensitive search on the Carrier field with the carrier parameter and is defaulted to search for all carriers.
  • Perform a case-insensitive search on the OriginCityName field with the origin parameter and is defaulted to search for all origin cities.
  • Perform a case-insensitive search on the DestCityName field with the destination parameter and is defaulted to search for all destination cities.
  • Sort the results by the AvgTicketPrice in descending order.

Once your flights_template is created, you should render the template without any params to make sure the query is crafted correctly with default values. If the render looks good, you'll want to run some sample searches to test out the search template. For example, try searching for flights by "Logstash Airways" from "Berlin" to "New York" with a results size of 10 per page.

Your es1 node has a Kibana instance that can be accessed in your local web browser by navigating to the public IP address of the es1 node (example: http://public_ip). To log in, use the elastic user with the password elastic_acg.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?