0
0
Elasticsearchquery~30 mins

Term query in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
Elasticsearch Term Query Basics
📖 Scenario: You are working with an Elasticsearch index that stores information about books in a library. Each book has fields like title, author, and genre.Your task is to find books that exactly match a specific genre using a term query.
🎯 Goal: Build an Elasticsearch term query to find all books where the genre field exactly matches the value "Science Fiction".
📋 What You'll Learn
Create an Elasticsearch index mapping with fields: title, author, and genre.
Add a configuration variable for the genre to search for, named search_genre with the value "Science Fiction".
Write a term query that searches the genre field for the exact value in search_genre.
Complete the query JSON structure to be ready for execution.
💡 Why This Matters
🌍 Real World
Searching for exact matches in a large collection of documents, such as finding books by genre in a library database.
💼 Career
Understanding term queries is essential for roles involving search engine development, data indexing, and backend search optimization.
Progress0 / 4 steps
1
Create the Elasticsearch index mapping
Create a JSON object called index_mapping that defines an Elasticsearch index mapping with fields title, author, and genre, all of type keyword.
Elasticsearch
Need a hint?

Use a dictionary with mappings and properties keys. Set each field's type to keyword.

2
Add the search genre variable
Create a variable called search_genre and set it to the string "Science Fiction".
Elasticsearch
Need a hint?

Assign the exact string "Science Fiction" to the variable search_genre.

3
Write the term query
Create a JSON object called term_query that uses a term query to search the genre field for the exact value stored in search_genre.
Elasticsearch
Need a hint?

Use the term key inside query and set the genre field to the variable search_genre.

4
Complete the query JSON structure
Add a size field to the term_query JSON object and set it to 10 to limit the number of results returned.
Elasticsearch
Need a hint?

Add the size key at the top level of term_query and set it to 10.