0
0
Elasticsearchquery~15 mins

Match query in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
Elasticsearch Match Query
📖 Scenario: You are working with a collection of books stored in Elasticsearch. Each book has a title and an author. You want to find books by searching for words in their titles.
🎯 Goal: Build an Elasticsearch match query to find books whose titles contain a specific word.
📋 What You'll Learn
Create an index called books with sample book documents
Set a search word in a variable called search_word
Write a match query to find books with titles matching search_word
Print the search query JSON
💡 Why This Matters
🌍 Real World
Searching text fields in Elasticsearch is common for websites and apps that show books, articles, or products.
💼 Career
Knowing how to write match queries helps you build search features and work with Elasticsearch in many developer and data roles.
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 represent a book with keys title and author. Use these exact entries: {"title": "The Great Gatsby", "author": "F. Scott Fitzgerald"}, {"title": "Great Expectations", "author": "Charles Dickens"}, and {"title": "The Grapes of Wrath", "author": "John Steinbeck"}.
Elasticsearch
Need a hint?

Use a list with three dictionaries exactly as shown.

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

Assign the string "Great" to the variable search_word.

3
Write the match query
Create a variable called match_query that holds a dictionary representing an Elasticsearch match query. The query should search the title field for the value in search_word. Use this exact structure: {"query": {"match": {"title": search_word}}}.
Elasticsearch
Need a hint?

Use a nested dictionary with keys "query", "match", and "title".

4
Print the match query
Write a print statement to display the match_query variable.
Elasticsearch
Need a hint?

Use print(match_query) to show the query.