Managing synonyms in OpenSearch

Synonyms let users find content with different words, but a careless rollout can shift rankings and break analysis. This page explains how to add and maintain them on self-hosted OpenSearch.

On this page

Why managing synonyms in OpenSearch needs a plan before the first rule

A site or application team usually discovers the need for synonyms when users search for words that do not match the catalog. Shoppers type "sneakers" and get nothing because the product pages say "trainers," support staff search for an abbreviation that no document contains, or customers use a former brand name that the marketing team retired. In OpenSearch, the synonym token filter handles these cases by mapping terms during analysis, so a query for one form can match documents that use another. Because the mapping happens in the analyzer rather than in the query, every synonym change is a change to how text is indexed and searched, and that is where the rollout risk sits.

Before writing the first rule, decide how the synonyms will be supplied. The filter accepts an inline list of synonyms or a file referenced through synonyms_path, and it reads Solr format by default, with WordNet also supported. Inline lists are easy to review in index settings but get unwieldy as the vocabulary grows. A synonym file is easier for merchandisers or search engineers to maintain, but it must be deployed to every node that loads the analyzer, and the team needs a process for distributing updates. The lenient option can skip lines that fail to parse, which keeps a bad rule from blocking the analyzer, but it can also hide a broken file. Confirm the file format and parsing behavior against the OpenSearch synonym token filter documentation before you choose it.

Inline synonym lists or synonym files: which fits your team

Inline synonyms sit in the index settings, so the people who can change index settings control the rules. That usually means platform or search engineers. A synonyms_path file separates the rules from the index definition, which lets a content owner, merchandiser or domain expert maintain a text file without touching the index configuration. Ask who will own synonym changes week to week, because that answer usually settles the choice. Inline lists work well when the rule set is short and stable. A file works better when the list is long, changes often, or is maintained by people outside the engineering team. Consider also whether those editors need access to your repository or ticketing system to make a change at all.

  • Inline lists: Rules are part of the index settings and travel with the index definition.
  • Synonym files: Rules live in a separate file that editors can change without modifying index settings.
  • Access boundary: A file adds an extra place to grant write access, so plan who holds that permission.
  • Rule volume: Long, frequently edited lists are harder to maintain in index settings.
  • Ownership: Name one accountable owner for each synonym set, whatever the storage method.

Confirm which teams will edit rules and what permissions they already have in your version of OpenSearch.

Synonym filter options and when each fits

This table compares the synonym token filter settings and the synonym versus synonym_graph choice, with the point where each fits and what to confirm before use. Read each row as a decision: pick the setting that matches where your rules live, the format your team maintains, and how multi-word synonyms must behave at query time.

Setting or choiceWhen it fitsWhat to confirm before use
Inline synonyms (synonyms)A short, stable list kept in the index settings and changed rarely, such as a handful of brand or abbreviation pairs.Who owns the list, how changes are reviewed, and that the full rule set stays readable in index settings and version control.
Synonyms file (synonyms_path)A longer or frequently edited list that merchandising or search teams maintain outside the index definition.The file path on every node, how it is distributed, and how updates reach search-time analyzers without a full reindex.
Solr format (default)Teams starting from scratch or with existing Solr synonym files that they want to reuse.That your rules use the Solr syntax, including how equivalent terms and explicit mappings are written.
WordNet formatTeams that already maintain WordNet-style lexical data for English word relationships.That your source file follows the WordNet format the filter expects, and that the terms fit your domain vocabulary.
Lenient parsing (lenient)Large imported lists where a few malformed rules should not block the whole analyzer from loading.Which rules were skipped, since lenient parsing hides errors. Test the skipped lines against expected matches before you rely on it.
synonym filterSynonyms applied at index time, where the expanded terms are stored in the index.Whether multi-word synonyms behave correctly for phrase queries, and that changes will require reindexing to take effect.
synonym_graph filterSynonyms applied at search time or in analyzers that handle multi-word expansions, where phrase matching must keep token positions correct.That the analyzer is used only at search time, as the synonym_graph filter is intended for query-side analysis, and that query tests cover multi-word terms.

Synonym or synonym graph: how multi-word terms change query behavior

The choice between the synonym and synonym_graph token filters decides how a multi-word synonym such as "New York, NYC" affects token positions, and therefore how phrase queries behave. The older synonym filter expands multi-word rules by inserting tokens at positions that can misalign with the original text, which can make phrase and proximity matches return results you did not intend. The synonym_graph filter preserves the token graph, so it is the appropriate choice when multi-word terms appear in search analyzers. Confirm the behavior for your deployed version in the OpenSearch synonym token filter documentation before you commit to a filter.

Where the analyzer runs is the second design decision. A synonym filter placed in the index analyzer expands terms at indexing time, which means the index must be rebuilt to change a rule, while a filter in the search analyzer applies at query time and can be updated more easily. Applying the same synonym set at both index and search time usually duplicates matches and inflates scores, so pick one side for each field and document the choice. Check the current guidance on search-time analyzer updates in the refresh search analyzer documentation for your version.

Test every decision with the _analyze API before rollout. Run the representative queries your users actually type, including multi-word phrases, abbreviations and terms with several synonyms, against the index analyzer and the search analyzer separately. Inspect the returned tokens, their positions and the position increments, and confirm that a phrase query matches the documents it should. Keep these queries in version control alongside the synonym files so that each rule change is re-tested against the same cases. Your team should decide who approves synonym changes and how they are verified before deployment.

How a synonym rule travels from file to query results

The rule starts in a synonym file in the cluster's config directory or in an inline list in the index settings, and the synonym filter reads it when the analyzer is built. The same filter can run at index time and at search time, so a change to the rule set reaches stored documents only after a reindex, while a search-time change needs a _reload_search_analyzers call on the index. Check that the analyzer named in the mapping is the one that picked up the new rules, and test the output before ranking changes are judged.

Where a synonym rule is read, applied at index and search time, and where a reload or reindex is required.

Setting up synonyms without breaking relevance

This sequence moves synonym rules from a query log review to a monitored production analyzer, with a check at each stage so that new equivalences improve matching without shifting rankings for queries that already work.

  1. Inventory the query log for mismatched terms

    Pull a sample of recent search queries that returned zero or weak results, along with the terms users reformulated to in the same session. Group them into candidate equivalence pairs, such as abbreviations, product codes, brand names and regional spellings, and note which ones your team agrees should match. Each candidate should carry a short justification and an owner from the search or content team. The step is done when you have a reviewed candidate list and a set of queries that show the problem, which you will reuse as a relevance query set in a later step.

  2. Choose the synonym format and filter

    Decide between the synonym token filter and the synonym graph token filter, and between inline synonyms and a synonyms_path file. The OpenSearch synonym filter accepts inline synonyms or a file path, supports Solr and WordNet formats with Solr as the default, and offers a lenient option that skips rules it cannot parse. Record the choice, the format and whether lenient parsing is on, and confirm the decision against the current synonym token filter documentation for your OpenSearch version. The step is done when the decision is written down with its reason, such as keeping rules in version control as a file.

  3. Write the rules in a test index

    Create a test index with a custom analyzer that uses your chosen filter, then load the candidate rules as inline synonyms or from a file in a test path. Keep the test index separate from production so that a bad rule cannot affect live search. Set lenient handling deliberately: with it on, a malformed rule is skipped silently, so the team should review the rule file for skipped lines rather than assume every rule loaded. The step is done when the test index is created without errors and the file or inline list matches the reviewed candidate list.

  4. Verify tokens with the analyze API

    Run the analyze API against the test index for each candidate pair and for a sample of unchanged queries. Confirm that the expected terms appear in the token output at the same positions, and that multi-word synonyms behave as intended, since graph-aware filters handle multi-token expansions differently from the basic filter. Check that single-word queries you did not target still produce the same tokens as before. The step is done when every candidate pair produces the expected tokens and no unrelated query changes its token output.

  5. Check ranking on the relevance query set

    Run the queries from the inventory, plus a set of queries that already perform well, against a copy of the production index with the test analyzer applied. Compare the top results before and after the change, and judge whether new matches appear without pushing known good results down. Keep the comparison in a table that records each query, the old top results and the new top results. The step is done when the owner signs off that the targeted queries improved and the control queries are unchanged or changed only in ways the team accepts.

  6. Deploy the synonym file to the cluster

    Place the reviewed synonym file on every node at the path the analyzer references, or deliver it through your standard configuration process, and update the index settings to point at the new analyzer. Make the change through your normal change control so the file, the index settings and the approval are tracked together. Confirm that the file is present and readable on all nodes before you apply the change. The step is done when the file is in place on each node and the analyzer configuration matches the approved test index.

  7. Reload or reindex analyzers

    Check the refresh analyzer documentation to confirm whether your version can reload a search analyzer from an updated file without reindexing. If the search analyzer can be reloaded, run the reload for the target index and confirm the reload completed. If the change affects index-time analysis, plan a reindex instead, because existing documents keep their old tokens until they are reindexed. The step is done when the analyzer reflects the new rules, and a query for one of the new synonyms returns the expected documents from the production index.

  8. Monitor results and maintain the rules

    After deployment, watch zero-result rates, reformulation patterns and the control queries from the relevance set for a period your team defines. Review the synonym file on a schedule, removing rules that no longer match real queries and adding rules from new log findings through the same steps. Keep the file in version control so every change has an author and a reason. The step is done when the team has a recurring review owner, a dashboard or report for the monitored queries, and a documented process for proposing new rules.

Where synonym rollouts go wrong

Synonym changes look small but touch indexing, search and every node in the cluster. The risks below share one root cause: the rule file, the analyzer chain and the index state must agree, and a mismatch usually fails quietly rather than with an error.

Over-broad rules pull unrelated results

A rule such as pants, trousers is harmless in one catalog and damaging in another, where it may merge distinct products or match a term used in a different sense. Each rule widens recall for every query containing its terms, so a single careless line can move many results. Review a sample of queries before and after each change, and keep rules narrow and owned by a named person who can explain why each one exists.

Synonym token filter docs

Index-time changes need reindexing

When the synonym filter sits in the index analyzer, existing documents keep the tokens they were indexed with, so new rules do not apply to them until the documents are reindexed. The result is that some documents match the new synonyms and others do not. Decide up front whether the filter belongs at index time or search time, and plan the reindex window and rollback if the filter must change at index time.

One node with a stale file

When synonyms are loaded from a file through synonyms_path, each node reads its own copy. If a file is updated on some nodes and not others, the same query can return different results depending on which node coordinates it. Distribute the file through the same configuration process as the rest of the cluster, and check that every node reports the same file version after a change.

Unparseable rules dropped silently

The lenient option makes the filter skip rules it cannot parse instead of failing. That keeps the cluster running, but a typo or unsupported syntax line disappears without an error in the response, so the synonym you expected may never apply. Test the rule file with lenient turned off in a non-production environment, and compare the expected synonyms against query results after every deployment.

Synonym filter parsing options

Analyzers that differ between index and search

A synonym filter in only one of the index or search analyzers produces tokens that do not line up, so queries miss documents that should match. Mismatched tokenizers, stemmers or filter order cause the same problem. Keep the analyzer definitions in version control, compare them for each field, and test sample terms with the analyze API before release.

Who can change synonyms and how changes are reviewed

Synonym rules change search results for every user, so the first decision is who may edit them. Treat the synonym file (for example, the file referenced by synonyms_path) and the index settings that hold inline synonym lists as production configuration, not as content that anyone with cluster access can adjust. Restrict write access to the repository or configuration store that holds these files, and restrict index settings changes to a small set of named administrators or a deployment pipeline. Confirm how your OpenSearch Security roles are scoped for index settings and analyzer updates, since a user who can update index settings may be able to change analysis without touching the file at all. The OpenSearch Security plugin provides role-based access control, so map these permissions to specific roles and test them with a non-admin account before go-live.

Keep synonym files in version control and require a review step before merge. A reviewer should check each rule for its effect on existing queries, not only for syntax. Ask the author to record the reason for each rule and the search terms it is meant to fix, so that a later reviewer can tell whether it is still needed. Before deployment, run the candidate file against a representative set of queries in a non-production cluster and compare the top results with the current behavior. A synonym that improves one query can push a document out of the top results for another, so keep a fixed query set and check it each time the file changes.

Audit trails close the loop. Confirm that your OpenSearch Security audit logging records the events you need, such as index settings updates and changes to analyzers, and that those logs are kept outside the cluster where administrators cannot alter them. Pair the audit log with the version control history so you can answer who changed a rule, when it reached production and who approved it. Whether these controls meet a specific policy or assessment requirement depends on your configuration process and the framework you follow, so confirm the audit scope and retention with your compliance team and with the OpenSearch security documentation for your version.

Limits to confirm in your environment

Synonym behavior depends on the OpenSearch version, the analyzer chain and how rules reach the cluster. The items below are the assumptions most likely to break a synonym change in production, and each one should be tested on your own rules and cluster before rollout.

Format support in your version

Confirm which synonym formats your OpenSearch version accepts. The synonym token filter supports Solr and WordNet formats, with Solr as the default, but the details of each format, including how multi-word terms and expansions are written, should be checked against the version you run. Write a small set of representative rules in each format you plan to use and confirm that every rule is parsed as you intended before you copy them into production files.

Synonym filter docs

Whether reload applies to your analyzer

Confirm that the refresh mechanism works for your analyzer setup before you depend on it. Updating a synonym file does not change search behavior until the search analyzer is reloaded, and the refresh path is typically limited to search analyzers that use a synonym filter with a synonyms_path file. Test with an index that matches your production mapping, and confirm which analyzer chain your fields use, including any index-time analyzers that a reload will not update.

Refresh analyzer docs

File size and rule count

Ask how large your synonym file can grow before reloads, startup and query latency become a concern on your hardware. The number of rules, the number of expansions per rule and the file size all affect analyzer build time and memory on each node. Measure these with your full synonym list on a cluster sized like production, and record the results so you can compare them when the list grows.

Behavior of lenient parsing

Confirm what lenient parsing skips on your rules before you enable it. The lenient option lets the filter skip rules it cannot parse, which keeps the cluster running but can silently drop synonyms that users expect to work. Load the file with lenient turned off first to surface errors, then compare search results for a fixed set of test queries with and without the option, so that a skipped rule shows up as a test failure instead of a relevance complaint.

Synonym filter placement in analysis

Confirm whether your analyzer uses the synonym filter or the synonym graph filter, and whether it runs at index time or search time. Where the filter sits in the token chain changes which tokens are matched, especially with stemming and multi-word terms. Test the analyze output for queries that contain multi-word synonyms, since the same rule can produce different matches depending on filter order.

Questions teams ask before adding synonyms

What drives the cost of adding synonyms to OpenSearch?

The cost depends mostly on how many synonym groups you need, how many languages and fields they touch, and how much of the relevance work is done in-house. Most of the spend is people time: someone collects candidate terms from search logs and support tickets, a second person reviews them for false matches, and an engineer changes analyzers and tests the results. The one-time part covers the initial term list, analyzer design and test queries. The recurring part covers new terms, periodic review and reindexing when analyzers change. Ask any quote to separate these items and to name who reviews the synonym list after go-live.

How long does it take to get a first useful synonym rollout live?

The timeline depends on how quickly your team agrees on a first term list, how many indices use the analyzer, and whether your environment has a test cluster that mirrors production. A small, well-scoped list on one index moves faster than a multi-language catalog that needs analyzer changes across several indices. Reindexing time grows with document count, so large indices take longer to validate. No duration is fixed here. Ask for a written plan that lists the test cluster, the index sizes involved, and the approval steps before anything reaches production.

What does the work need from our internal teams?

You need three kinds of input. Search or product owners must supply the terms that matter to customers and the queries that currently fail. Engineers must own the analyzer configuration, index settings and deployment process. Support or merchandising staff should review synonym pairs, because a rule that looks correct to an engineer can change results in ways only domain experts notice. Security or platform teams should confirm where the synonym files are stored and who may change them, since these files alter what users see. Agree on who approves each change before the first rollout.

Can our team add synonyms to OpenSearch without outside help?

Yes, a team with OpenSearch experience can add synonyms alone, especially for a single language and a short list of terms. The synonym token filter accepts inline synonyms or a synonyms_path file, so the mechanics are not difficult. The harder parts are judging relevance, testing for side effects on unrelated queries and handling reloads safely on a live cluster. If no one on your team has tuned search relevance before, or if the catalog spans several languages, a partner can help with the design and review. Decide this by checking who will own the list six months after launch.

When does a partner make sense for synonym work?

A partner helps most when the synonym work is one part of a larger search project, when the team lacks time to test relevance properly, or when several indices and languages must stay consistent. DeployOpen plans and implements search on self-hosted OpenSearch inside the client's own infrastructure, and most engagements are fixed-scope with deliverables and timelines agreed in writing before work starts. Ask any partner to describe how it measures the effect of a synonym change, how it limits unintended matches, and what it hands over for your team to maintain.

What goes wrong when synonym rules are added carelessly?

The most common failures are broad terms that pull unrelated results into top positions, bidirectional rules that change meaning for a short query, and rules that conflict with stemming or language analyzers. Malformed rules can also stop an analyzer from loading. Using the lenient option can keep a cluster running after a bad rule, but it skips rules silently, so a broken line may go unnoticed. Test each change against a fixed set of queries before and after the change, and check the logs for parse errors after every reload.

Should we keep synonyms inline or in a synonym file?

Inline synonyms suit a short, stable list defined directly in the index settings. A synonyms_path file suits longer lists that change often, because editors can work in a file under version control. The OpenSearch synonym token filter supports Solr and WordNet formats, with Solr as the default, so confirm which format your existing lists use before you convert them. Changes to the file require the analyzer to be reloaded, so plan that step as part of your release process. The refresh search analyzer documentation describes how to apply updated analyzers to an index that is already in use.

How DeployOpen scopes and delivers synonym work

DeployOpen approaches synonyms in OpenSearch as a planned change to a self-hosted cluster that your team will run. We agree the scope in writing first, then build, test and document the synonym rules inside your own infrastructure, so your team can maintain them after handover.

How we scope

  • Inventory the indices, analyzers and fields that will use synonym filters before any rules are written
  • Agree in writing which synonym sets, formats and update paths are in scope for the engagement
  • Confirm which OpenSearch version and analyzer chain your cluster runs, and who owns rule changes afterward
  • Engagements are fixed-scope, so scope, deliverables and timelines are agreed in writing before work starts

How we build

  • Configure synonym or synonym graph filters in your index analyzers, using inline lists or synonyms_path files as agreed
  • Load and test synonym files in a non-production cluster and check analysis output for representative queries
  • Test lenient parsing behavior and reloading of search analyzers against your own synonym sources before cutover
  • Record the search-time and index-time placement of each filter so later changes stay predictable

How we hand over

  • Deliver the synonym files, index mappings and analyzer configuration in version-controlled form with a change record
  • Document the rule format, the reload procedure and the testing steps your team should repeat for each change
  • Walk your search and platform engineers through the reload process and a set of sample relevance checks
  • Agree the handover acceptance criteria in the written scope so both sides know when the work is complete

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers for synonym sets that keep changing
  • Retainer work can cover new synonym entries, analyzer changes after OpenSearch version upgrades, and relevance regression checks
  • Ask any partner for a quote built from the written scope, including who maintains rules after handover and how changes are approved

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.