0
0
Elasticsearchquery~30 mins

Full-text search engine concept in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
Build a Simple Full-Text Search with Elasticsearch
📖 Scenario: You are creating a small search engine for a library's book collection. The library wants to quickly find books by searching words in the title or description.
🎯 Goal: Build a basic Elasticsearch setup that stores book data and allows searching for books by keywords in their titles or descriptions.
📋 What You'll Learn
Create an Elasticsearch index called library with appropriate mappings for text fields
Add a few book documents with title and description fields
Write a search query to find books matching a keyword in either title or description
Display the search results showing the book titles
💡 Why This Matters
🌍 Real World
Full-text search engines help users find relevant information quickly in large collections of documents, like books, articles, or websites.
💼 Career
Understanding how to set up and query Elasticsearch is valuable for roles in data engineering, backend development, and search engine optimization.
Progress0 / 4 steps
1
Create the Elasticsearch index with mappings
Write a command to create an Elasticsearch index called library with mappings for title and description fields as text type.
Elasticsearch
Need a hint?

Use the PUT method to create the index and define mappings with properties for title and description as text.

2
Add book documents to the index
Add three book documents to the library index with these exact entries:
1: title: 'The Great Gatsby', description: 'A novel set in the Jazz Age.'
2: title: 'Learning Elasticsearch', description: 'A guide to full-text search.'
3: title: 'Cooking 101', description: 'Basic recipes for beginners.'
Elasticsearch
Need a hint?

Use POST /library/_doc/<id> to add each book with the exact title and description.

3
Write a search query for a keyword
Write a search query to find books in the library index where the keyword search appears in either the title or description fields. Use a multi_match query with query set to search and fields set to ["title", "description"].
Elasticsearch
Need a hint?

Use GET /library/_search with a multi_match query specifying query as search and fields as ["title", "description"].

4
Display the titles of the search results
Write a command to display only the title fields from the search results of the previous query. Use _source filtering to include only title in the output.
Elasticsearch
Need a hint?

Add "_source": ["title"] to the search query to show only the titles in the results.