# Elasticsearch Features and Practical Usage
🗣️ You want "laptop" and "notebook" to find the same products. Synonyms absorb those variations and rephrasings, and the Synonyms API lets you manage them with no reindexing.
🏷️ Title: Synonyms API / synonym token filter
🔗 URL:
📘 Overview
Synonyms improve relevance by matching documents that express the same concept with different words, and they help with domain-specific vocabulary and common misspellings. Managing synonym sets as independent resources through the Synonyms API lets multiple analyzers reference them and removes the need to reindex on updates.
⚙️ How It Works
There are two rule formats.
・Equivalent (bidirectional): comma-separated terms like `laptop, notebook, computer`. With `expand=true` all terms map to each other; with `expand=false` they collapse to the first term as the canonical form.
・Explicit (one-way): `i-pod, i pod => ipod` replaces the left-hand terms with the right-hand term via `=>`.
Two token filters exist, `synonym` and `synonym_graph`; `synonym_graph` is recommended because it handles multi-word synonyms correctly. Applying synonyms at search time means updates require no reindexing.
🛠️ Practical Usage
Create a synonym set with the Synonyms API and reference it from an `updateable: true` analyzer.
```
PUT _synonyms/my-synonym-set
{ "synonyms_set": [
{ "id": "1", "synonyms": "laptop, notebook, computer" },
{ "id": "2", "synonyms": "pc => personal computer" } ] }
```
Point a `synonym_graph` filter's `synonyms_set` at this set and wire it into your search-time analyzer (`search_analyzer`). With `updateable: true`, updating the set via the API automatically reloads the associated analyzers, so changes take effect immediately. Validate the result beforehand with the `_analyze` API.
💡 Use Cases
This is ideal for an e-commerce relevance-improvement loop. Analyze search logs to find rephrasings that returned zero hits, add them to the synonym set through the Synonyms API, and they take effect instantly with no reindexing. You can continuously eliminate "searched but not found" cases.
⚠️ Caveats
Always use `synonym_graph` for multi-word synonyms; the legacy `synonym` filter breaks position information. Large synonym lists consume heap, and exceeding 95% trips the circuit breaker. With `lenient=false` the index can go red, so in production prefer API-managed sets over inline definitions.
#
Elasticsearch# #
SearchRelevance#