Unifying Search Terms with Algolia Synonyms: Practical Steps and Trade‑offs
Learn how to use Algolia’s synonym feature to boost search recall, step‑by‑step, with real API examples, trade‑offs, and validation tips.
21 Aug 2025, 13:19 UTC

Problem: Fragmented Search Results
When users type different words that mean the same thing—"TV" vs. "television" or "iPhone" vs. "Apple iPhone"—Algolia returns separate sets of hits. The result is low recall: some relevant items never surface because the query string doesn’t match the indexed data exactly.
Thesis: Use Synonyms to Boost Recall, but Keep an Eye on Precision
Synonyms are a powerful tool for improving recall, but they can also introduce noise if overused. The key is to define them deliberately, test the impact, and manage them programmatically for large sets.
Synonym Types in Algolia
Algolia offers two synonym categories that are exposed through the API and dashboard:
- Multi‑way ("synonym"): All listed terms are considered interchangeable. A hit matches if any of the terms appears in the document.
- One‑way ("oneWay"): A single input term expands to one or more synonyms, but the reverse is not true.
Both types are stored per index; you can also apply them globally by creating a dedicated "synonyms" index and using the indexSynonyms feature, but that is an advanced use case.
Implementation Steps
Plan your synonym set. Map the most common misspellings, abbreviations, and alternate names to a single canonical keyword. Keep the list to a few hundred entries for maintainability.
Create synonyms via the API. Example for a multi‑way synonym in Node.js (Algolia JavaScript client v4):
const algoliasearch = require('algoliasearch'); const client = algoliasearch('YourApplicationID', 'YourAdminAPIKey'); const index = client.initIndex('products'); const synonym = { objectID: 'syn_tv', // unique ID type: 'synonym', synonyms: ['tv', 'television'] }; index.saveSynonym(synonym).then(({ objectID }) => { console.log('Synonym saved', objectID); });For a one‑way synonym:
const oneWay = { objectID: 'oneway_iphone', type: 'oneWay', input: 'iphone', synonyms: ['apple iphone', 'iphone 15'] }; index.saveSynonym(oneWay);Batch synonyms for large sets. Use
index.saveSynonyms([syn1, syn2, ...])to apply many at once. This reduces the number of API calls and keeps your code tidy.Verify the changes. Retrieve a synonym by its
objectID:index.getSynonym('syn_tv').then(console.log);Or list all synonyms with pagination:
async function listAllSynonyms() { const iterator = index.browseSynonyms(); for await (const syn of iterator) { console.log(syn.objectID, syn.type, syn.synonyms || syn.input); } } listAllSynonyms();Check the dashboard’s Synonyms tab to see the visual representation.
Test search impact. Run controlled queries before and after adding synonyms. For example, search for
tvand compare the number of hits and the top results. Use Algolia’ssearchForFacetValuesor log search analytics to quantify recall improvement.
Trade‑offs and Limitations
- Precision loss. Synonyms broaden the query; unrelated items may surface if the canonical term appears in an unrelated context.
- API usage. Each synonym update requires an API call. For very large synonym sets, consider batching to keep the number of calls low.
- Version drift. Manual edits in the dashboard can diverge from your source‑of‑truth configuration. Keep a versioned JSON file and sync via the API.
- Global synonyms. If you need synonyms that apply across multiple indices, you must manage them in a dedicated index and use the
indexSynonymsfeature, which adds complexity. - Custom logic. Algolia does not provide a built‑in “custom” synonym type. If you need locale‑specific rules or case‑insensitive matching, implement that logic in your application code before sending the query to Algolia.
Practical Validation Checklist
- Confirm synonym IDs are unique and descriptive.
- Verify that
index.getSynonym(objectID)returns the expected definition. - Run a query that previously returned
nhits and ensure it now returns at leastnhits plus the expected synonyms. - Check Algolia’s Search Analytics to see if click‑through rates improve, indicating better relevance.
- Monitor API usage after a batch update to ensure the cost is acceptable.
Conclusion: When to Use Synonyms and When to Skip Them
Synonyms are ideal for:
- Short, highly‑used search terms with multiple common variants.
- Bridging product naming gaps across international markets.
- Improving recall for niche categories where users may use domain‑specific jargon.
Skip or limit synonyms when:
- The index is very large and API usage would become a cost concern.
- Terms are highly ambiguous and can lead to irrelevant matches.
- You prefer to rely on Algolia’s built‑in typo tolerance and faceting for recall.
By defining a focused synonym list, applying it via the batch API, and validating with controlled queries, you can dramatically improve search recall while keeping precision in check.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.