Spelling correction with OpenSearch suggesters

Spelling correction in OpenSearch uses term suggesters for single words and phrase suggesters for whole queries, with edit distance and suggest-or-correct choices that decide how users experience typos. This page explains the options, setup sequence and trade-offs for self-hosted clusters.

On this page

How spelling correction in OpenSearch works and when your search needs it

A product catalog or support site team often finds that users type a model number with a transposed digit or misspell a content title, and the results page comes back empty. OpenSearch offers term and phrase suggesters for did-you-mean behavior on a self-hosted cluster, so the search can point users to the likely intended query. The term suggester works on individual words. It looks at each token in the query, finds index terms within a set edit distance, and ranks candidates by how often they occur. The phrase suggester works on the whole query, so it can consider how words combine and suggest a corrected phrase, which matters when a misspelled word only makes sense in context.

Edit distance is the number of single-character changes (insertions, deletions, substitutions and transpositions, depending on the settings) needed to turn one string into another. A small distance catches typos like a dropped letter while avoiding unrelated words. A larger distance catches more errors but produces more noisy suggestions and costs more to compute. The term suggester exposes this as a setting you tune against your own query logs, not a value to copy from a tutorial. Check the parameters and their defaults for your OpenSearch version in the OpenSearch did-you-mean documentation before you commit to them.

Add suggesters before you rely on fuzzy matching in queries when the goal is to show users what they meant, not silently return different results. Fuzzy queries broaden the match and can surface surprising hits, while suggestions let the user confirm the correction. Decide early whether you will auto-correct or only suggest, because that choice changes how you measure success and how you explain results. Pull a sample of zero-result queries from your logs first: if most failures are typos in product or content names, a suggester is a good fit. If they are synonyms or vocabulary gaps, the fix lies elsewhere.

Which suggester and settings fit which search query

This table compares the term and phrase suggesters and the settings that shape their output, including edit distance, suggest-only versus automatic correction, and sort and frequency choices. Match your query type to an option, then check its trust risk and the test to run before release. Automatic correction carries the highest trust risk, so most teams should start with suggestions that users accept themselves.

OptionWhen it fitsRelevance or trust riskTest before release
Term suggesterQueries where one word is misspelled, such as a typo in a product or topic termCan rewrite valid rare words, brand names or product codes into common wordsRun logged misspellings and proper nouns from your own catalog and check the top suggestion
Phrase suggesterMulti-word queries where correcting each word alone ignores the surrounding contextCosts more per query and can propose phrases that few documents containMeasure latency at peak query volume and check suggestions for known multi-word phrases
Lower edit distanceShort catalog terms, strict domains, or teams that want few and conservative correctionsMisses common typos in longer words, so users still get zero resultsTest a set of real typos grouped by word length and count which ones go uncorrected
Higher edit distanceLong words and forgiving search experiences where recall of typos matters mostProduces unrelated suggestions and false corrections that erode user trustReview precision of the top suggestion on a sample of valid queries, not only typos
Suggest only (did-you-mean)Most public and internal search pages, where the user chooses whether to accept the correctionLow risk, though many users ignore the prompt, so recovery stays limitedTrack clicks on the suggestion and how often zero-result queries end in a successful search
Automatic correctionZero-result queries in a catalog where the intended term is clear and easy to verifySilently changes what the user searched for and can hide the original query from themCheck queries that had results before correction and confirm users can see the query that ran
Sort and frequency choicesWhen several candidates tie, so you prefer candidates that appear more often in your indexCommon words can outrank the rare term the user meant, such as a niche product nameTest rare but valid terms and confirm that frequent words do not replace them
Suggestion mode for existing wordsDeciding whether words already present in the index should still receive suggestionsSuppressing suggestions for valid rare words can hide a genuine correctionCompare results with the mode on and off for words that exist in your index but are uncommon

Setting up did-you-mean in a self-hosted OpenSearch index

This sequence takes did-you-mean from a suggestion source field to a tested front-end prompt, with a check at each stage so you know the suggestions match what users actually misspell before anyone sees them.

  1. Choose the index and suggestion source field

    The search or platform engineering team decides which index and field supply the vocabulary for suggestions, usually the same text field users search on or a dedicated copy of it. Confirm the field is analyzed with the language analyzer your search already uses, and note whether product names, codes or other non-dictionary terms appear in it, since those will show up as suggestions unless you exclude them. The step is done when the field name, analyzer and index are written down and a sample of documents shows the terms you expect. Check the term frequencies for the field on a copy of the index so you know which words the suggester will draw from.

  2. Define the analyzer and suggester fields

    Engineers map the source field so the suggester has what it needs, then confirm the mapping on a non-production index. For single words, plan a term suggester; for whole queries, plan a phrase suggester that reads from a shingle-based field. Record the edit distance and prefix length you start with, since these control how far a misspelling can drift from a real term. The step is done when the index creates without errors and a test query against a known word returns a suggestion for a deliberately misspelled version of it.

  3. Add the suggest block to the search body

    The developer adds a suggest section next to the query in the search request, with the suggester type, field, edit distance and size. Keep the suggest request separate from the main query so results and suggestions can be read independently, and do not change ranking in this step. Run the request against the test index with a handful of misspelled queries and confirm that the response includes a suggest object with options for each misspelled term. The step is done when the response shape is stable and the search results are unchanged for correctly spelled queries.

  4. Test suggestions against real misspelled queries

    Pull a sample of queries from your search logs that returned few or no results, and mark the ones that were clearly misspelled. Run each one through the suggest request and record whether the top suggestion matches the intended term or phrase. Review false suggestions, such as valid rare words corrected to common ones, and adjust edit distance, minimum word length or the source field until the sample looks right. The step is done when a reviewer has signed off on the suggestions for the sample, and you have a list of queries that still fail with the reason for each.

  5. Measure empty-result rates on a test set

    Build a test set of queries with known outcomes, including correctly spelled queries, misspelled queries and queries for terms that legitimately return nothing. Run the test set through the search API before and after the suggester is added to the front end, and compare the share of queries that return zero results. Confirm that correctly spelled queries do not gain unwanted suggestions and that the empty-result rate for misspelled queries falls for the cases you targeted. The step is done when the before and after figures are recorded alongside the test set, so the change can be repeated after future index or analyzer changes.

  6. Show suggestions in the front end

    The front-end team displays the top suggestion as an explicit prompt, such as a link that asks whether the user meant the suggested term, and keeps the original query as the one that runs unless the user accepts the suggestion. Avoid silently rewriting the query, because users then cannot see what was searched and support teams cannot reproduce results. Test the prompt in the interface with a set of misspelled queries and confirm that accepting the suggestion runs the corrected search and that dismissing it leaves the original results in place. The step is done when both paths have been tested on the staging environment and the behavior is written into the search specification.

  7. Track suggestion use and review regularly

    Log when a suggestion is shown, accepted or dismissed, along with the original query and the result count, so the team can see which suggestions help users. Review the log on a regular schedule, adding frequent false suggestions to an exclusion list and checking whether new product or content terms need to be added to the source field. Confirm that the logging does not store sensitive query text beyond your retention policy. The step is done when a recurring review has a named owner and the logging design has been approved by whoever governs search data in your organization.

Suggesting versus auto-correcting queries

The first decision is whether a corrected query should be offered to the user or applied automatically. A did-you-mean suggestion, built from a term suggester or phrase suggester, leaves the user in control: the original results stay on screen and the user chooses whether to accept the correction. Automatic correction reruns the search with the corrected terms, so the user sees results they did not ask for. That can help when most queries are plainly misspelled, but it changes what the user sees without their consent. Any auto-corrected results page should show a clear notice, such as "Showing results for [corrected query]," with an explicit search for the original query instead link that reruns the exact text the user typed. Build that path before launch, and test that the original query is preserved in the search box, the URL and the analytics events.

Risk concentrates in content where a near-match is a different thing. Product names, model numbers, SKUs, error codes, part numbers, drug names, case citations and legal terms often sit one edit away from a common word, and an automatic rewrite can silently send a customer to the wrong item or a clinician to the wrong medication. Multilingual content adds another failure mode: a correction suggested from one language's dictionary may be a valid word in another language, and terms borrowed between languages can look misspelled. The safe default for these fields is to suggest, not to rewrite. Ask the content owners for a list of protected terms and exclude those fields or tokens from correction, and confirm the suggester settings against your own index mappings before deciding.

Choose the mode from your data and from observed user behavior, not from a general preference. Review the query logs for the share of zero-result queries that a suggestion would fix, sample the suggestions a human would reject, and check whether users in your domain expect a correction at all. A catalog shopper may welcome an automatic fix, while a researcher searching exact identifiers usually will not. Use the Search Relevance Workbench or a manual query set to compare results before shipping either mode, and record which teams approved the final behavior. Because suggester thresholds, candidate counts and the choice of mode can all change with index content, plan a periodic review rather than treating the decision as permanent.

How index content and query logs shape suggestion quality

A did-you-mean feature is only as good as the vocabulary it draws from and the queries it is tuned against. The cards below cover the factors that shape suggestion quality, and what to check in the cluster before you change edit distance.

Vocabulary in source fields

Term suggesters build candidates from the terms actually stored in the indexed fields, so a misspelled word in your catalog or content can become a suggestion. Check which fields the suggester reads, then sample their terms for typos, product codes and boilerplate. Clean the source vocabulary before tuning edit distance, because a higher distance only widens the pool of bad candidates.

Did-you-mean docs

Term frequency thresholds

Suggesters can rank candidates by how often they occur in the index, and rare terms may be dropped or ranked low depending on the settings you choose. A single-occurrence typo can look like a valid word if it is never filtered out. Check term frequency distributions for the fields you suggest from, and confirm which frequency settings your OpenSearch version exposes before relying on them.

Analyzer choice

The analyzer on a suggested field decides which tokens exist, including stemming, lowercasing and stop word removal. A suggestion can point to a stemmed form such as a root word that users never type, which makes the result look wrong. Compare the analyzer output for a few sample terms on the suggested field and on the query side, and keep both aligned.

Language mix

Content in several languages puts unrelated words into one vocabulary, so a German term can be suggested as a near-match for an English query. Brand names and loanwords add further noise across languages. Identify which language each field contains, and check whether separate per-language fields would give cleaner candidates than one shared field.

Noisy and brand-specific terms

Product codes, model numbers, internal names and brand terms are often misspelled on purpose or fall outside any dictionary, so the suggester may correct them into common words. A search for a SKU could return a suggestion for an unrelated term. Build an exclusion list of protected terms or review candidates with a domain owner before you widen the edit distance.

Query log used for tuning

Your query log shows what users really type, including misspellings that the index never contains. Tuning against only indexed text can miss the errors people actually make, while raw logs carry abuse and test traffic. Sample the log for a representative period, separate zero-result queries from successful ones, and confirm your logging and retention policy covers this use before you tune.

How a user query moves through suggesters and results

The flow starts when a shopper or reader submits a query in the application's search box. The application search layer sends it to the OpenSearch coordinating node, which fans the request out to the term and phrase suggesters running against the index data. The suggestions come back alongside the normal hits, and the application decides whether to show a did-you-mean prompt or to rerun the search with the corrected text. Check that the suggestion path and the main results path are logged separately, so you can tell how often users accept corrections.

Query path from the search box through term and phrase suggesters to the response decision.

Access control and logging for suggestion features

Suggestions are generated from indexed terms, so they can expose content that a user cannot open through normal search. The cards below cover the controls that decide what a suggestion reveals, how requests are logged, and what the team should verify in its own cluster before users see did-you-mean output.

Suggestions can reveal indexed terms

A term or phrase suggester reads terms from the index, so a misspelled query can return a suggestion built from a document the user cannot open. Treat suggestion output as a read path to the index. For example, a restricted HR document's unique surname could surface as a correction for a typo by a user outside HR. Ask the team to test this with a non-privileged test user before launch.

Did-you-mean docs

Document-level security on suggestions

OpenSearch Security provides document-level security, which limits which documents a role can match. Confirm whether the suggester's candidate terms are drawn only from documents visible to the requesting role, or whether terms from the whole index can appear. Run the same suggestion request as users with different roles and compare the output. Record the result as evidence for the design review.

Field-level security and field masking

Field-level security restricts which fields a role can read, and field masking hides field values behind a hashed or partial form. Suggestions built on a field that a role cannot read are the risk to check. Where a sensitive field is used as a suggestion source, plan a separate suggestion field with limited content, or exclude that field from suggester input.

Role design for search clients

Search applications usually connect with a service account that holds broad read access. Create roles for each application or user group, map them to the identity backend, and grant each only the indices and fields it needs. Confirm how the application passes user identity to the cluster, since a shared service account can bypass per-user document and field rules.

Audit logging of search requests

Audit logs record requests to the cluster, which lets a team see who asked for suggestions and which indices were queried. Decide in advance which request categories to log, where logs are stored, and who can read them. Suggestion requests can contain user-typed text, so confirm that the log retention and access policy match your privacy obligations.

OpenSearch security docs

TLS for client traffic

Suggestion requests carry user input and results travel back to the browser or application server. Enable TLS for node and client traffic so queries and suggestions are not sent in clear text on the network. Confirm that the application server, load balancer and cluster all use certificates your team issues and rotates on a schedule.

Questions teams ask before adding spelling correction

How much effort does adding spelling correction to OpenSearch take?

Effort depends less on the suggester syntax than on the data and the search experience around it. The API calls for a term suggester or phrase suggester are short to write. The larger work is confirming which fields need suggestions, choosing the analyzer those fields use, testing suggestions against real queries, and deciding how the front end displays them. Teams with a clean index and a clear product owner move faster. Teams with mixed languages, many fields, or no query logs usually spend more time on evaluation before any code ships.

How long does a first version of spelling correction usually take?

A first version depends on the number of search fields, the languages involved, and how much evaluation the team requires before release. Plan for a short build and a longer evaluation period, since suggestions must be checked against real misspellings and against queries that are correct but unusual, such as product codes or names. Ask any partner to break the schedule into discovery, build, test against sample queries, and release steps, and to state which of those steps depend on your content owners or query data being available.

What must our team provide before the work starts?

Most delays come from missing inputs rather than from OpenSearch itself. Prepare the following before the work starts:

  • Sample search queries from logs, including queries that returned zero results
  • The list of indices and fields that users search, with the analyzers they use today
  • Named content owners who can approve dictionary terms, brand names, and exclusions
  • A test environment that matches the production index mapping closely enough to measure results
  • Languages and locales the search must support

Without query logs, the team will be guessing which misspellings matter.

Can our internal team add spelling correction without outside help?

Yes, a capable search engineer can add term and phrase suggesters on their own, since the feature is part of the OpenSearch search API and is documented. The harder part is tuning: deciding edit distance, minimum term length, and when to show a suggestion. An internal team should plan time for that tuning and for reviewing results with product owners. Outside help is most useful when the team lacks search relevance experience, has several languages to cover, or needs the change delivered within a fixed scope and schedule.

Should the search automatically correct misspelled queries or only suggest a fix?

For most search experiences, suggesting a correction is the safer default. The user sees a did-you-mean prompt and decides whether to accept it, so a wrong suggestion costs one click rather than hiding what the user typed. Automatic correction suits narrow domains where misspellings are common and the correct term is nearly always obvious, such as a catalog with a limited vocabulary. Whichever you choose, log what users typed, what was suggested, and whether they accepted it, so the decision can be reviewed with data.

What does ongoing spelling correction tuning cost over time?

Ongoing cost is mostly people time and recurs as content and queries change. Expect periodic review of suggestion quality, updates to exclusion lists for brand names and product codes, and re-testing after OpenSearch version upgrades or index mapping changes. Infrastructure cost is usually small compared with that review work, because suggesters run against the index you already maintain. Ask any provider which of these tasks are included in a fixed-scope delivery and which fall under a separate support or retainer agreement.

How do we scope a fixed-price spelling correction engagement?

A fixed-price scope works best when it names the fields, languages, and suggester types covered, the number of query sets used for testing, the review rounds with content owners, and the exact deliverables such as configuration, test results, and operating notes. DeployOpen agrees scope, deliverables, and timelines in writing before work starts, and provides a quote from that written scope rather than a published price list. Ask for the exclusions in writing too, such as additional languages, new fields added later, or changes to the front-end interface.

How DeployOpen scopes and delivers search spelling correction

DeployOpen plans, implements, tests, documents and supports self-hosted OpenSearch inside your own infrastructure, including the suggester configuration behind did-you-mean. Engagements start with a written scope that sets which query types, fields and behaviors the spelling correction will cover before any code or index changes begin.

How we scope

  • We confirm which fields and query types need term suggestions and which need phrase suggestions for whole queries.
  • We agree in writing whether results auto-correct or only show a did-you-mean prompt, with the reasoning recorded.
  • We define edit distance, sizing and suggestion thresholds to test against a sample of your real query logs.

How we build

  • We configure term and phrase suggesters in your cluster and wire them into your search request flow.
  • We tune edit distance and candidate settings against sample queries, including misspellings, brand names and domain terms.
  • We check suggestion behavior across the language analyzers your application already uses before release.

How we hand over

  • We document the suggester settings, query templates, fallback logic and the reasons behind each tuning decision.
  • We provide test query sets with expected suggestions so your team can rerun them after changes or upgrades.
  • We walk your engineers through the configuration in your own environment and agree on ownership of each setting.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after handover.
  • Retainer work can cover retesting suggestions after index changes, OpenSearch version upgrades and new query patterns.
  • Pricing follows from the written scope. Ask us to confirm which items are one-time and which recur before you sign.

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.