0
0
Elasticsearchquery~30 mins

Why text analysis enables smart search in Elasticsearch - See It in Action

Choose your learning style9 modes available
Why text analysis enables smart search
📖 Scenario: You are building a simple search feature for a small online bookstore. You want users to find books easily by typing words related to the book titles or descriptions.To do this, you will use Elasticsearch's text analysis features to break down the text into searchable parts and make the search smarter.
🎯 Goal: Build a basic Elasticsearch index with text analysis enabled, add some book data, and perform a search that shows how text analysis helps find relevant books.
📋 What You'll Learn
Create an Elasticsearch index with a custom analyzer that uses a lowercase filter
Add three book documents with titles and descriptions
Use a match query to search for a word in the book titles or descriptions
Print the search results showing matched books
💡 Why This Matters
🌍 Real World
Text analysis is key in search engines to break down and understand user queries and documents, making search results more relevant and user-friendly.
💼 Career
Knowing how to configure text analysis in Elasticsearch is important for roles in backend development, data engineering, and search engine optimization.
Progress0 / 4 steps
1
Create the Elasticsearch index with text analysis
Create an Elasticsearch index called books with a custom analyzer named my_analyzer that uses the standard tokenizer and the lowercase filter.
Elasticsearch
Need a hint?

Use the PUT method to create the index with settings.analysis.analyzer and mappings.properties.

2
Add book documents to the index
Add three book documents to the books index with these exact details:
1. title: "The Great Gatsby", description: "A classic novel set in the 1920s."
2. title: "Great Expectations", description: "A story about personal growth and ambition."
3. title: "The Art of War", description: "An ancient Chinese military treatise."
Elasticsearch
Need a hint?

Use POST /books/_doc/1, _doc/2, and _doc/3 to add each book with the exact titles and descriptions.

3
Search for books using text analysis
Write a search query using GET /books/_search with a match query on the title field to find books matching the word great.
Elasticsearch
Need a hint?

Use a match query on the title field with the word great.

4
Display the search results
Print the titles of the books returned by the search query for great to show how text analysis helps find both "The Great Gatsby" and "Great Expectations".
Elasticsearch
Need a hint?

Show the titles of the books found by the search to demonstrate the effect of text analysis.