Bird
Raised Fist0
Elasticsearchquery~20 mins

Synonym handling in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Synonym Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this synonym filter configuration?
Given the following Elasticsearch analyzer configuration with synonyms, what tokens will be produced for the input text "quick fox"?
Elasticsearch
{
  "settings": {
    "analysis": {
      "filter": {
        "synonym_filter": {
          "type": "synonym",
          "synonyms": [
            "quick,fast",
            "fox,red fox"
          ]
        }
      },
      "analyzer": {
        "synonym_analyzer": {
          "tokenizer": "standard",
          "filter": ["lowercase", "synonym_filter"]
        }
      }
    }
  }
}

Input text: "quick fox"
A["quick", "fast", "fox", "red", "fox"]
B["quick", "fox"]
C["fast", "red", "fox"]
D["quick", "fast", "fox"]
Attempts:
2 left
💡 Hint
Think about how synonyms expand tokens during analysis.
🧠 Conceptual
intermediate
1:30remaining
Which synonym type supports multi-word synonyms in Elasticsearch?
Elasticsearch supports different synonym types. Which synonym type allows you to define multi-word synonyms like "red fox" as a synonym for "fox"?
A"synonym_graph" filter
B"synonym" filter with <code>expand: true</code>
C"stop" filter
D"keyword" filter
Attempts:
2 left
💡 Hint
Multi-word synonyms require special handling to preserve token positions.
🔧 Debug
advanced
2:00remaining
Why does this synonym filter cause a query parsing error?
Given this synonym filter snippet, why does Elasticsearch return a parsing error when indexing documents? "synonyms": [ "fast, quick", "fox => red fox" ]
Elasticsearch
synonyms: [
  "fast, quick",
  "fox => red fox"
]
AThe arrow syntax (=>) is only valid in the "synonym" filter, but the list is missing commas.
BThe arrow syntax (=>) is invalid in the "synonym" filter; it requires the "synonym" filter with <code>expand: false</code>.
CThe arrow syntax (=>) is valid only if <code>expand</code> is set to false, which is missing here.
DThe arrow syntax (=>) is invalid in the "synonym" filter; it requires the "synonym_graph" filter.
Attempts:
2 left
💡 Hint
Check the rules for using arrow syntax in synonym filters.
📝 Syntax
advanced
2:00remaining
Which synonym filter configuration is syntactically correct for multi-word synonyms?
Select the correct Elasticsearch synonym filter configuration snippet that supports multi-word synonyms without errors.
A
{
  "type": "synonym",
  "synonyms": ["red fox, fox"]
}
B
{
  "type": "synonym_graph",
  "synonyms": ["red fox, fox"]
}
C
{
  "type": "synonym",
  "synonyms": ["red fox =&gt; fox"]
}
D
{
  "type": "synonym_graph",
  "synonyms": ["red fox =&gt; fox"]
}
Attempts:
2 left
💡 Hint
Multi-word synonyms with arrow syntax require a specific filter type.
🚀 Application
expert
2:30remaining
How many tokens are produced by this analyzer with synonyms and stop words?
Given this analyzer configuration and input text, how many tokens are produced? Analyzer config: { "tokenizer": "standard", "filter": ["lowercase", "stop_filter", "synonym_filter"] } Filters: - stop_filter removes: "the", "a" - synonym_filter synonyms: "quick,fast" "fox,red fox" Input text: "The quick brown fox jumps over a lazy dog"
A11
B9
C10
D12
Attempts:
2 left
💡 Hint
Count tokens after stop word removal and synonym expansion.

Practice

(1/5)
1. What is the main purpose of synonym handling in Elasticsearch?
easy
A. To find search results that include different words with the same meaning
B. To speed up the indexing process
C. To store data in multiple languages automatically
D. To encrypt search queries for security

Solution

  1. Step 1: Understand synonym handling concept

    Synonym handling allows Elasticsearch to match words that mean the same, improving search results.
  2. Step 2: Identify the main goal

    The goal is to find results with different words but same meaning, not speed or encryption.
  3. Final Answer:

    To find search results that include different words with the same meaning -> Option A
  4. Quick Check:

    Synonym handling = find similar meaning words [OK]
Hint: Synonyms help find words with same meaning [OK]
Common Mistakes:
  • Thinking synonyms speed up indexing
  • Confusing synonyms with encryption
  • Assuming synonyms translate languages automatically
2. Which of the following is the correct way to define a synonym filter in Elasticsearch settings?
easy
A. "filter": { "synonym_filter": { "type": "keyword", "synonyms": ["quick,fast"] } }
B. "filter": { "synonym_filter": { "type": "stop", "synonyms": ["quick,fast"] } }
C. "filter": { "synonym_filter": { "type": "synonym", "synonyms": ["quick,fast"] } }
D. "filter": { "synonym_filter": { "type": "stemmer", "synonyms": ["quick,fast"] } }

Solution

  1. Step 1: Identify correct filter type for synonyms

    The filter type for synonyms must be "synonym" to handle synonym lists.
  2. Step 2: Check the filter definition syntax

    "filter": { "synonym_filter": { "type": "synonym", "synonyms": ["quick,fast"] } } correctly uses "type": "synonym" and defines synonyms as a list.
  3. Final Answer:

    "filter": { "synonym_filter": { "type": "synonym", "synonyms": ["quick,fast"] } } -> Option C
  4. Quick Check:

    Synonym filter type = "synonym" [OK]
Hint: Synonym filters use type "synonym" [OK]
Common Mistakes:
  • Using wrong filter types like stop or stemmer
  • Not defining synonyms as a list
  • Misspelling "synonym" type
3. Given this analyzer configuration, what will be the tokens produced for the text "fast car"?
{
  "analysis": {
    "filter": {
      "synonym_filter": {
        "type": "synonym",
        "synonyms": ["fast,quick"]
      }
    },
    "analyzer": {
      "synonym_analyzer": {
        "tokenizer": "standard",
        "filter": ["lowercase", "synonym_filter"]
      }
    }
  }
}
medium
A. ["fast", "quick", "car", "car"]
B. ["fast", "quick", "car"]
C. ["quick", "car"]
D. ["fast", "car"]

Solution

  1. Step 1: Analyze the text with the synonym filter

    The synonym filter maps "fast" to "quick", so both tokens appear for "fast".
  2. Step 2: List all tokens after analysis

    Tokens are "fast", "quick" (synonym), and "car" (unchanged).
  3. Final Answer:

    ["fast", "quick", "car"] -> Option B
  4. Quick Check:

    Synonym adds "quick" token for "fast" [OK]
Hint: Synonym filter adds synonyms as extra tokens [OK]
Common Mistakes:
  • Ignoring synonym addition and listing only original tokens
  • Replacing original token instead of adding synonym
  • Duplicating tokens unnecessarily
4. You defined a synonym filter but your search results do not include synonyms. What is the most likely mistake?
medium
A. You used the synonym filter in the index but not in the search analyzer
B. You forgot to add the synonym filter to the analyzer's filter list
C. You defined synonyms as a string instead of a list
D. You used the synonym filter with the wrong tokenizer

Solution

  1. Step 1: Understand how synonym filters affect search

    Synonyms must be applied in the analyzer used during search to affect results.
  2. Step 2: Identify common setup mistake

    Often synonyms are applied only at index time, missing search analyzer usage.
  3. Final Answer:

    You used the synonym filter in the index but not in the search analyzer -> Option A
  4. Quick Check:

    Synonyms must be in search analyzer too [OK]
Hint: Apply synonym filter in both index and search analyzers [OK]
Common Mistakes:
  • Adding synonym filter only at index time
  • Not including synonym filter in search analyzer
  • Misconfiguring synonyms as string instead of list
5. You want to improve search for a product catalog where users may search for "tv", "television", or "smart tv". How should you configure synonyms to handle these terms effectively?
hard
A. Apply synonyms only at search time to avoid changing indexed data
B. Define synonyms only for "tv" and "television" but exclude "smart tv" because it has two words
C. Use a stop filter to remove "smart" and then define synonyms for "tv" and "television"
D. Define synonyms as: "tv, television, smart tv" in a synonym filter and apply it in both index and search analyzers

Solution

  1. Step 1: Define all related terms as synonyms

    Include "tv", "television", and "smart tv" together to cover all user queries.
  2. Step 2: Apply synonym filter in both index and search analyzers

    This ensures synonyms work during indexing and searching for best results.
  3. Final Answer:

    Define synonyms as: "tv, television, smart tv" in a synonym filter and apply it in both index and search analyzers -> Option D
  4. Quick Check:

    Synonyms cover all terms and apply at both stages [OK]
Hint: Include all terms and apply synonyms at index and search [OK]
Common Mistakes:
  • Ignoring multi-word synonyms like "smart tv"
  • Applying synonyms only at search time
  • Using stop filter incorrectly to remove words
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard