0
0
Elasticsearchquery~30 mins

First search query in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
First search query
📖 Scenario: You have a small collection of books stored in Elasticsearch. You want to find books by their title.
🎯 Goal: Build a simple Elasticsearch query to find books with a specific word in their title.
📋 What You'll Learn
Create an index called books with sample book data
Set a search keyword variable called search_word
Write a query to find books where the title contains search_word
Print the titles of the matching books
💡 Why This Matters
🌍 Real World
Searching documents or records by keywords is a common task in many apps like libraries, stores, or websites.
💼 Career
Understanding how to build and run search queries is important for roles in data analysis, backend development, and search engine management.
Progress0 / 4 steps
1
Create the books index with sample data
Create a variable called books that holds a list of dictionaries. Each dictionary should have id and title keys with these exact entries: {'id': 1, 'title': 'The Great Gatsby'}, {'id': 2, 'title': 'Great Expectations'}, {'id': 3, 'title': 'The Grapes of Wrath'}.
Elasticsearch
Need a hint?

Use a list with dictionaries for each book.

2
Set the search keyword
Create a variable called search_word and set it to the string 'Great'.
Elasticsearch
Need a hint?

Just assign the string 'Great' to search_word.

3
Write the search query logic
Create a list called results that contains all books from books where the search_word is found in the title. Use a list comprehension with book as the iterator variable.
Elasticsearch
Need a hint?

Use a list comprehension to filter books by title containing search_word.

4
Print the titles of matching books
Use a for loop with variable book to print the title of each book in results.
Elasticsearch
Need a hint?

Use a for loop to print each matching book's title on its own line.