Reader small image

You're reading from  Getting Started with Elastic Stack 8.0

Product typeBook
Published inMar 2022
PublisherPackt
ISBN-139781800569492
Edition1st Edition
Right arrow
Author (1)
Asjad Athick
Asjad Athick
author image
Asjad Athick

Asjad Athick is a security specialist at Elastic with demonstratable experience in architecting enterprise-scale solutions on the cloud. He believes in empowering people with the right tools to help them achieve their goals. At Elastic, he works with a broad range of customers across Australia and New Zealand to help them understand their environment; this allows them to build robust threat detection, prevention, and response capabilities. He previously worked in the telecommunications space to build a security capability to help analysts identify and contextualize unknown cyber threats. With a background in application development and technology consulting, he has worked with various small businesses and start-up organizations across Australia.
Read more about Asjad Athick

Right arrow

Chapter 10: Building Search Experiences Using the Elastic Stack

Welcome to Section 3 of Getting Started with the Elastic Stack. The last two sections focused on a detailed introduction and providing practical guidance for each of the core components of the Elastic Stack. You should already be able to appreciate some of the problems you can solve by using these components together. This section will dive deeper into the theme of building end-to-end solutions on top of the Elastic Stack. This chapter focuses on building search capabilities on top of the Elastic Stack.

At its core, Elasticsearch is a full-text search engine with the capability to index and query large volumes of data at speed. Searching is considered an essential and central aspect of the user experience in a wide range of applications and use cases.

The most obvious form factor for good search functionality is that of a search box on a website or app, allowing users to find content relevant to them (typically from...

Technical requirements

This chapter explores various aspects of building search functionality for your data. The examples require access to an Elasticsearch cluster running on your local machine to follow along.

The code for this chapter can be found on the GitHub repository for the book:

https://github.com/PacktPublishing/Getting-Started-with-Elastic-Stack-8.0/tree/main/Chapter10

The chapter uses a collection of recipes scraped from the internet to illustrate the search functionality we are implementing. Navigate to Chapter10/dataset in the code repository for this book and follow the instructions to load the dataset as shown:

  1. The following file is provided in the folder:

recipe-template.json contains an Elasticsearch index template for the given dataset, detailing the schema/mappings for the fields in the dataset.

  1. Load the index template provided by running load.sh. Enter your Elasticsearch cluster URL, username, and password when prompted:
    ./load.sh...

An introduction to full-text searching

The simplest way to search for or retrieve a document is typically to match the search term or text with values in your index or datastore. In Elasticsearch, this type of search happens on keyword fields using term-level queries. As we saw in Chapter 3, Indexing and Searching for Data, term-level queries are useful when you know precisely what you're looking for. A full list of query options is available in the reference guide:

https://www.elastic.co/guide/en/elasticsearch/reference/8.0/term-level-queries.html

For example, if a user wanted to retrieve all recipes written by one or more authors, term-level queries can do the job quickly and efficiently:

GET recipes/_search
{
  "query": {
    "terms": {
      "author": [
        "Staff",
        "Jim...

Implementing features to improve the search experience

Building powerful search experiences means making it easy and seamless for users to quickly find information relevant to them. The following features build on top of the standard textbox-powered search applications to improve this experience.

This section demonstrates the search features in action with reference to the Recipe Search Service demo application.

Autocompleting search queries

Autocomplete functionality assists the user by providing suggestions on what they might be looking for. For example, a user who starts to type the word chicken can be shown a list of options with the prefix chicken to help them quickly narrow down on the content they're looking for.

Figure 10.4 – Autocompletion suggestions for recipes with the prefix "chicken"

Elasticsearch provides out-of-the-box capability for autocompletion using the completion field type.

The following index mapping...

Summary

In this chapter, we went through the details of a full-text search and how it works in Elasticsearch. We started by exploring full-text search concepts and how they enable some of the search experiences you may want to build. We also looked at how Elasticsearch APIs can be used to run different types of queries to retrieve relevant results.

Next, we explored some common features that are part of good search experiences. We looked at implementing features such as autocompletion, search query suggestions, filtering/faceted searches, pagination, and the ordering of search results. The chapter concluded by putting all the concepts together in the form of a demo application. The Recipe Search Service application implements the features discussed to demonstrate the full-text search functionality in action.

In the next chapter, we move on to understanding how the Elastic Stack can be used to observe applications and infrastructure to detect and respond to issues in your environment...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Getting Started with Elastic Stack 8.0
Published in: Mar 2022Publisher: PacktISBN-13: 9781800569492
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Asjad Athick

Asjad Athick is a security specialist at Elastic with demonstratable experience in architecting enterprise-scale solutions on the cloud. He believes in empowering people with the right tools to help them achieve their goals. At Elastic, he works with a broad range of customers across Australia and New Zealand to help them understand their environment; this allows them to build robust threat detection, prevention, and response capabilities. He previously worked in the telecommunications space to build a security capability to help analysts identify and contextualize unknown cyber threats. With a background in application development and technology consulting, he has worked with various small businesses and start-up organizations across Australia.
Read more about Asjad Athick