A character filter is a preprocessing step that modifies the text before tokenization. It changes or removes characters to prepare the text for analysis.
Click to reveal answer
beginner
Name two built-in character filters in Elasticsearch.
Two built-in character filters are html_strip which removes HTML tags, and mapping which replaces characters or strings based on a mapping.
Click to reveal answer
intermediate
How does the mapping character filter work?
The mapping filter replaces specified characters or strings with other characters or strings before tokenization. For example, it can replace accented letters with plain letters.
Click to reveal answer
beginner
Why use character filters before tokenization?
Character filters clean or normalize text by removing unwanted characters or replacing them. This helps tokenizers produce consistent tokens and improves search accuracy.
Click to reveal answer
intermediate
Show a simple example of a custom character filter using mapping in Elasticsearch.
This replaces 'æ' with 'ae' and 'œ' with 'oe' before tokenization.
Click to reveal answer
What is the main purpose of a character filter in Elasticsearch?
AModify text before tokenization
BCreate tokens from text
CStore indexed documents
DRun search queries
✗ Incorrect
Character filters change or clean text before it is split into tokens.
Which character filter removes HTML tags from text?
Ahtml_strip
Bmapping
Clowercase
Dstop
✗ Incorrect
The html_strip filter removes HTML tags before tokenization.
What does the mapping character filter do?
ARemoves stop words
BConverts text to lowercase
CReplaces characters or strings based on rules
DSplits text into tokens
✗ Incorrect
Mapping replaces specified characters or strings with others before tokenization.
When are character filters applied in the analysis process?
AAfter tokenization
BOnly during search queries
CDuring indexing only
DBefore tokenization
✗ Incorrect
Character filters run before tokenization to prepare the text.
Which of these is NOT a function of character filters?
AReplacing characters
BSplitting text into tokens
CRemoving unwanted characters
DNormalizing text
✗ Incorrect
Splitting text into tokens is done by tokenizers, not character filters.
Explain what character filters do in Elasticsearch and why they are important.
Think about how text is prepared before breaking it into words.
You got /4 concepts.
Describe how you would use a mapping character filter to replace special characters in text.
Consider replacing accented letters with plain letters.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a character_filter in Elasticsearch analyzers?
easy
A. To split text into tokens after analysis
B. To modify text before tokenizing by replacing or removing characters
C. To store documents in the index
D. To sort search results by relevance
Solution
Step 1: Understand character_filter role
Character filters act on raw text before tokenization to clean or replace characters.
Step 2: Differentiate from other components
Tokenizers split text into tokens, and other parts handle indexing or sorting, not character filters.
Final Answer:
To modify text before tokenizing by replacing or removing characters -> Option B
Quick Check:
Character filters = modify text pre-tokenizing [OK]
Hint: Character filters act before tokenizing text [OK]
Common Mistakes:
Confusing character filters with tokenizers
Thinking character filters sort or store data
Assuming character filters work after tokenizing
2. Which of the following is the correct syntax to define a mapping character filter in Elasticsearch?
easy
A. "char_filter": {"my_mapping": {"type": "mapping", "mappings": ["ph=>f", "qu=>kw"]}}
B. "char_filter": {"my_mapping": {"type": "pattern_replace", "pattern": "ph", "replacement": "f"}}
C. "char_filter": {"my_mapping": {"type": "mapping", "pattern": "ph", "replacement": "f"}}
D. "char_filter": {"my_mapping": {"type": "replace", "mappings": ["ph=>f"]}}
Solution
Step 1: Identify correct type and keys for mapping filter
The mapping filter uses "type": "mapping" and a "mappings" array with string replacements.
Step 2: Check syntax correctness
"char_filter": {"my_mapping": {"type": "mapping", "mappings": ["ph=>f", "qu=>kw"]}} correctly uses "type": "mapping" and "mappings" with array of strings like "ph=>f".
Final Answer:
"char_filter": {"my_mapping": {"type": "mapping", "mappings": ["ph=>f", "qu=>kw"]}} -> Option A
Quick Check:
Mapping filter syntax = type mapping + mappings array [OK]
Hint: Mapping filters use type 'mapping' and 'mappings' array [OK]
Common Mistakes:
Using pattern_replace keys for mapping filter
Wrong type name like 'replace' instead of 'mapping'
Using 'pattern' and 'replacement' keys in mapping filter
C. The replacement string 'ph=>f' is incorrect format
D. The key should be 'mappings' not 'mapping'
Solution
Step 1: Check correct key for mapping filter
The mapping filter requires the key 'mappings' (plural) for the array of replacements.
Step 2: Verify other parts
Type 'mapping' is valid, and the replacement string format "ph=>f" is correct.
Final Answer:
The key should be 'mappings' not 'mapping' -> Option D
Quick Check:
Key name must be 'mappings' for mapping filter [OK]
Hint: Use 'mappings' key (plural) for mapping filters [OK]
Common Mistakes:
Using 'mapping' instead of 'mappings'
Mistaking type name
Wrong replacement string format
5. You want to create a character filter that replaces all occurrences of 'cat' with 'dog' and removes digits from the text before tokenizing. Which configuration correctly combines these requirements?