📖 Scenario: You are building a simple search feature for a small library. You want to analyze the text of book titles so that searches work well by breaking text into words and lowering case.
🎯 Goal: Create an Elasticsearch index with the standard analyzer applied to the title field. Then test how the analyzer breaks down a sample book title.
📋 What You'll Learn
Create an index called library with a mapping for title field using the standard analyzer
Use the _analyze API to analyze the text "The Quick Brown Fox" with the standard analyzer
Print the tokens produced by the analyzer
💡 Why This Matters
🌍 Real World
Search engines use analyzers to break down text so users can find relevant results easily.
💼 Career
Understanding analyzers is important for roles involving search, data indexing, and text processing.
Progress0 / 4 steps
1
Create the index with standard analyzer
Create an index called library with a mapping where the title field uses the standard analyzer.
Elasticsearch
Hint
The standard analyzer is the default for text fields, but here you specify it explicitly in the mapping.
2
Set the text to analyze
Create a JSON object called analyze_request with the keys analyzer set to standard and text set to "The Quick Brown Fox".
Elasticsearch
Hint
The analyze API expects a JSON with analyzer and text keys.
3
Analyze the text using the standard analyzer
Use the _analyze API on the library index with the JSON object containing analyzer set to standard and text set to "The Quick Brown Fox".
Elasticsearch
Hint
The _analyze API shows how the text is split into tokens by the analyzer.
4
View the tokens produced by the analyzer
Print the tokens from the response of the _analyze API call. The tokens should be the, quick, brown, and fox.
Elasticsearch
Hint
The standard analyzer splits text into lowercase words, removing punctuation.
Practice
(1/5)
1. What does the standard analyzer in Elasticsearch do by default?
easy
A. Keeps punctuation and case intact
B. Breaks text into words, ignores punctuation and case
C. Only analyzes numbers and symbols
D. Removes all spaces and joins words
Solution
Step 1: Understand the role of the standard analyzer
The standard analyzer splits text into simple words by removing punctuation and ignoring case differences.
Step 2: Recall default behavior in Elasticsearch
It is the default analyzer and is designed for general text processing, making text lowercase and splitting on punctuation.
Final Answer:
Breaks text into words, ignores punctuation and case -> Option B
Quick Check:
Standard analyzer = splits words, ignores punctuation and case [OK]
Hint: Standard analyzer splits words and lowercases text [OK]
Common Mistakes:
Thinking it keeps punctuation
Assuming it preserves case
Believing it only analyzes numbers
2. Which of the following is the correct way to specify the standard analyzer in an Elasticsearch index mapping?
easy
A. "analyzer": "whitespace"
B. "analyzer": "simple"
C. "analyzer": "keyword"
D. "analyzer": "standard"
Solution
Step 1: Identify the analyzer name for standard analyzer
The standard analyzer is referenced by the string "standard" in Elasticsearch mappings.
Step 2: Compare with other analyzer names
Other analyzers like "simple", "keyword", and "whitespace" are different and not the standard analyzer.
Final Answer:
"analyzer": "standard" -> Option D
Quick Check:
Standard analyzer name = "standard" [OK]
Hint: Use "analyzer": "standard" to apply standard analyzer [OK]
Common Mistakes:
Using other analyzer names by mistake
Forgetting quotes around analyzer name
Confusing standard with simple analyzer
3. Given the text "Hello, World! Elasticsearch 7.10", what tokens will the standard analyzer produce?
medium
A. ["Hello", "World", "Elasticsearch", "7.10"]
B. ["hello,", "world!", "elasticsearch", "7.10"]
C. ["hello", "world", "elasticsearch", "7", "10"]
D. ["hello world elasticsearch 7 10"]
Solution
Step 1: Apply standard analyzer tokenization rules
The standard analyzer lowercases text and splits on punctuation and whitespace, so "Hello," becomes "hello", "World!" becomes "world".
Step 2: Analyze numbers and punctuation
Numbers separated by punctuation like "7.10" are split into "7" and "10" tokens.
Final Answer:
["hello", "world", "elasticsearch", "7", "10"] -> Option C
Quick Check:
Standard analyzer tokens = lowercase words split on punctuation [OK]
Hint: Standard analyzer lowercases and splits on punctuation [OK]
Common Mistakes:
Keeping punctuation attached to words
Not splitting numbers on dots
Preserving original case
4. You wrote this mapping snippet but your field is not analyzed as expected:
A. Analyzer name should be "standard", not "standard_analyzer"
B. Field type should be "keyword" instead of "text"
C. Analyzer must be defined under "settings", not "mappings"
D. Missing "index": true property
Solution
Step 1: Check the analyzer name used in mapping
The standard analyzer is named "standard". Using "standard_analyzer" is incorrect and causes the analyzer to not be found.
Step 2: Verify field type and analyzer placement
Field type "text" is correct for analyzed fields, and analyzer is correctly placed under "mappings". "index": true is default and not required.
Final Answer:
Analyzer name should be "standard", not "standard_analyzer" -> Option A
Quick Check:
Analyzer name must be exact "standard" [OK]
Hint: Use exact analyzer name "standard" in mappings [OK]
Common Mistakes:
Adding extra suffix to analyzer name
Changing field type to keyword for analyzed text
Misplacing analyzer in settings instead of mappings
5. You want to create a custom analyzer that uses the standard tokenizer but adds a lowercase filter and a stop word filter. Which of the following JSON snippets correctly defines this analyzer in Elasticsearch?