Building autocomplete with OpenSearch

Autocomplete on self-hosted OpenSearch comes down to where prefix work happens: at query time or at index time. This page explains the methods, their index size and typo trade-offs, and how to plan them before the build starts.

On this page

When autocomplete on OpenSearch needs an index-time design

Your product team wants the search box to suggest results as users type. On OpenSearch, you have four ways to build that behavior: prefix matching, edge n-gram matching, search as you type fields and completion suggesters. Prefix matching happens at query time, so the index stays close to its normal size and the query does the work on every keystroke. The other three happen at index time, so the cluster does the expensive analysis once during indexing and each query stays cheap. That split is the first decision to make, because it determines how much storage the suggestion data consumes and how much of the relevance behavior you can tune later.

Prefix matching fits small catalogs, low query volume, or fields where a few hundred milliseconds of extra latency is acceptable and the index must stay lean. It is also the simplest option to change, since you can alter the query without reindexing. Edge n-grams fit free-text fields such as product names or titles where users start typing the middle or beginning of a word and expect matches on partial tokens. Search as you type fields give you a managed set of subfields for prefix and shingle matching with less custom analyzer work, which suits most site search boxes. Completion suggesters are built for fast, prefix-only suggestions from a curated list, and they keep their data in a separate in-memory structure, so they fit a predictable set of terms such as navigation labels, popular queries or brand names.

The choice also controls index size and typo handling. Edge n-grams and shingles multiply the number of indexed terms, so ask your engineers to measure the index size on a representative sample before committing. Typo tolerance usually needs fuzzy queries on top of any of these methods, and fuzziness adds query cost that you should test under realistic concurrency. Confirm the current behavior of each option in the OpenSearch autocomplete documentation and in a test cluster that matches your version, since analyzer and suggester details can change between releases.

How each autocomplete method works in OpenSearch

Prefix matching is the simplest method. The index stores whole analyzed terms as they are, and the query expands the text the user has typed so far into a prefix query that matches any indexed term starting with those characters. All of the work happens at query time, so the index does not grow to accommodate autocomplete. The trade-off is that each keystroke runs a term expansion across the index, which gets more expensive as the vocabulary grows.

  • Work timing: Entirely at query time. Nothing extra is written during indexing.
  • Analyzer output: The analyzed terms of each document, unchanged. The prefix is applied to those terms when the query runs.
  • Index cost: Lowest of the four, because no additional terms are stored.
  • Typos and ranking: A misspelled first letter or a typo inside the prefix produces no match. Ranking depends on the scoring of the matched terms, so popular suggestions are not favored unless you add boosting.
  • Latency: Grows with vocabulary size and with how many terms share the typed prefix, so test it against your real term distribution.

Before choosing this method, confirm with a load test on a representative index that per-keystroke latency stays within your interface requirements.

Which autocomplete option fits which catalog and query pattern

This table compares prefix matching, edge n-grams, search-as-you-type fields and completion suggesters on the trade-offs that decide the choice: query cost, index growth, typo handling, mid-word matches and ranking control. Read each row against your own catalog size and query mix, then confirm index size on a sample of your real data before committing.

CriterionPrefix matching at query timeEdge n-grams at index timeSearch as you type or completion suggesters
Where the work happensQuery time, on each keystrokeIndex time, tokens stored in advanceIndex time, with suggestions stored in a dedicated structure or subfields
Query-time costGrows with term count and index size, so it suits small or moderate catalogs bestLow, since matches are simple term lookupsLow for completion suggesters; search-as-you-type queries are lightweight prefix lookups
Index size growthSmallest, because no extra tokens are storedGrows with indexed text length and gram range, so it needs careful settingsGrows with the number of suggestion inputs and shingle or prefix subfields
Typo toleranceWeak unless combined with fuzzy queries, which add costWeak on its own; fuzzy handling must be added deliberatelyCompletion suggesters offer fuzzy options; search-as-you-type can combine fuzzy matching, so confirm the behavior you need
Mid-word matchesLimited to the start of terms unless the query is widenedStrong, since grams match inside wordsLimited for completion suggesters, which match prefixes; search-as-you-type can cover some inner-word cases through subfields
Control over suggestion rankingModerate, through scoring and boosts on fieldsModerate, mainly through scoring and boosts on fieldsHigh for completion suggesters, which support explicit weights; confirm how weights interact with your ranking needs
Fit for short catalogsGood, with little setup and low storage overheadWorkable, but often more index than the catalog needsWorkable, though the extra structure may be more than a small list requires
Fit for large catalogsWeak at high query volume unless results are narrowed earlyGood for mid-word matching across many documents, with storage monitoredGood for fast prefix suggestions at scale, with index size and weights reviewed

Trade-offs between typo tolerance and index size

The core trade-off in autocomplete is where the work happens. Edge n-gram matching and search-as-you-type fields move work to index time: each indexed term is split into prefixes (or n-grams) so that a partial query matches a stored token directly. That makes matching fast, but every extra gram length and every extra prefix adds terms to the inverted index. Widening the minimum and maximum gram range, for example to cover short prefixes of one or two characters, multiplies the term count and can lower precision, because a short gram matches many unrelated words and pushes relevant suggestions down the list. Prefix matching at query time avoids that growth, but it pays for the lookup on every keystroke instead.

Typo tolerance adds a second cost. Fuzzy matching at query time, using the fuzziness parameter on a match or multi-match query, expands each typed term into candidate terms within an edit distance before scoring. Each keystroke repeats that expansion, so latency grows with the size of the term dictionary, the edit distance allowed and the number of terms in the query. Fuzziness also interacts with n-grams: if the index already holds many grams, a fuzzy query can match more candidates than intended. Limiting the fuzzy prefix length, keeping the edit distance at one for short inputs, and testing whether typo handling is better placed in a suggester than in every query are all options to compare.

Choose the range from measurements, not from defaults. Before deciding, build the index on a representative copy of your catalog or content with realistic field lengths and vocabulary, then record index size on disk, indexing time and p95 or p99 query latency at the keystroke rates your users produce. Score the top suggestions for a sample of real partial queries to see where precision drops as the range widens. Ask the team that owns the cluster how much disk and heap headroom they can commit, because that limit, not the average query, usually decides the range. Check the current OpenSearch documentation for autocomplete behavior in your version before you finalize settings, using the OpenSearch autocomplete documentation.

How to set up autocomplete on OpenSearch

This sequence moves an autocomplete feature from sample queries to a tuned, rollback-ready release, with each step producing a checkpoint the next one depends on. It keeps the method choice tied to real field data and latency measurements rather than assumptions.

  1. Collect sample queries and catalog fields

    Gather the partial queries users actually type from search logs, support tickets and site analytics, and list every field the suggestions could draw from, such as product names, categories, tags or document titles. Record which fields are user-facing, how often they change and whether any contain personal or restricted data that must stay out of suggestions. The step is complete when you have a written field inventory with sample queries grouped by intent and a named owner for each field.

  2. Choose the method for each field

    Decide per field whether prefix matching at query time, edge n-grams, a search-as-you-type field or a completion suggester fits best. OpenSearch applies prefix matching at query time, while edge n-grams, search-as-you-type and completion suggesters do their work at index time, so the trade-off is query cost against index size and write effort. Note which fields need typo tolerance and which need only fast prefix results. The step closes with a method table per field that the team reviews against the inventory from the previous step.

  3. Define analyzers and mappings in a test index

    Create a test index on a non-production cluster with the analyzers, tokenizers and field mappings chosen in the previous step, including any edge n-gram or search-as-you-type subfields and a separate analyzer for search time. Keep the analyzer definitions in version-controlled files so they can be reviewed and reproduced. Confirm the mapping behaves as intended by running the analyze API on sample inputs and checking the emitted tokens. The step is complete when the analysis output matches the expected prefixes for each sample query.

  4. Load representative data into the test index

    Load a copy of the catalog or document set that reflects real size, field length and character sets, not a small hand-written sample. Include edge cases such as accented characters, hyphenated names, very long titles and any suggestions you intend to exclude. Record index size on disk before and after loading, because index-time methods can grow the index substantially, and confirm document counts match the source. The step is complete when the test index holds representative data and its size is recorded for later comparison.

  5. Run suggestion queries with latency checks

    Send the sample queries from the first step to the test index, including prefixes of each length a user might type, and measure response time at the percentiles your interface requires. Include concurrent load that resembles peak traffic, since latency can differ sharply under concurrency. Check the suggestions for relevance, empty results and unwanted entries, and confirm that typo-tolerant matches appear only where you enabled them. The step closes with a results log showing latency and quality per field and method, which decides whether the design proceeds.

  6. Tune ranking and suppression rules

    Adjust field boosts, result limits, sort order and any suggestion weights based on the results log, and remove entries that should not appear, such as discontinued products or internal names. Repeat the query run after each change so you can see the effect of each adjustment rather than changing several settings at once. Record the final configuration in version control with the reasons for each setting. The step is complete when the team has signed off on the ranking against the sample queries and no open issues remain for the highest-traffic prefixes.

  7. Roll out with a tested rollback path

    Deploy the mappings and analyzers to the production cluster through your normal change process, and index into a new index rather than altering the live one, so the previous version stays available. Route a limited share of traffic to the new autocomplete, watch latency, error rates and index health, and keep an alias or application setting ready to point traffic back to the previous index. Confirm the rollback works by performing it once in a non-production environment before the release. The step is complete when the feature runs in production and the rollback has been rehearsed.

How index-time and query-time parts split the work

The flow starts with source documents passing through an index-time analyzer that writes edge n-grams, search-as-you-type subfields or completion inputs into the index. At query time, each keystroke reaches either a prefix query that runs against the existing terms or a completion suggester that reads the prebuilt structure, and the matches return to the front end as suggestions. Check which path each field uses, because index-time work is paid once at ingest and multiplies index size, while query-time prefix matching costs more per keystroke.

Index-time analysis and query-time lookups that feed autocomplete suggestions.

Access, logging and data controls for suggestion endpoints

Suggestions run against the same indices as full search, so they inherit the same exposure risks. The cards below cover the Security plugin controls that decide who can query suggestions, what they can see, and what gets recorded.

Role-based access on suggestion indices

Autocomplete queries hit the search index directly, so a user who can call the suggest endpoint can read whatever that index holds. Give the search application a role that grants read access only to the indices it needs, and keep write and admin permissions with the indexing pipeline. Check that each application client uses its own user rather than a shared administrative account, so permissions can be reviewed and revoked separately.

Security plugin docs

Field-level security for restricted fields

If a suggestion draws on fields such as customer names, internal product codes or employee data, those fields may need restriction beyond the index. Field-level security limits which fields a role can read, and field masking can return a hashed or obscured value instead of the raw content. Confirm which fields the suggestion query returns, because a suggestion that shows only a title can still expose a restricted field if it is included in the source.

Document-level security for tenant data

When one index holds records for several customers, departments or regions, document-level security filters results so that each role sees only its own documents. Autocomplete must apply the same filter as full search, or a suggestion can reveal a term from a document the user cannot open. Test with a user from each group and compare suggestions with what that user sees in search results.

TLS for client traffic

Suggestion requests are sent on every keystroke, often from browsers or front-end servers, so the traffic volume is high and the payloads include partial user input. Encrypt node and client traffic with TLS, and confirm that the application's HTTP client validates the cluster certificate. Plan certificate rotation before go-live, since a suggestion endpoint that fails on an expired certificate will fail silently for users.

Audit logging of query access

Audit logs record who accessed the cluster and what they did, which matters when suggestion queries can reveal sensitive terms. Decide which categories to enable for the suggest path, since every keystroke creates a request and logging all of them increases storage. Route audit output to a store with its own retention and access controls, and confirm who can read the logs, because the log itself contains the typed input.

Keeping sensitive text out of suggestion inputs

Completion suggesters and edge n-gram fields store the prefixes they are built from, so anything indexed for suggestions is copied into additional structures. Exclude personal data, credentials, health details and unreleased product names from suggestion fields unless the business case is documented. Review the mapping before indexing, and test whether a short prefix returns records a user should not see.

Questions teams ask before building autocomplete on OpenSearch

What drives the cost of building autocomplete on OpenSearch?

The main drivers are catalog size, the number of fields that feed suggestions, the number of languages, the typo rules you want, and how often the index must be rebuilt. Each one adds analysis work, index storage and testing. Ask any partner to price these as separate line items: discovery and data review, index design, query design, typo and language tuning, performance testing, and handover. Setup is largely one-time. Ongoing costs are the hosting you already pay for, plus any retainer for tuning, upgrades and relevance changes as your catalog grows.

Can our internal team build autocomplete on OpenSearch without a partner?

Yes, if the team already runs OpenSearch or Elasticsearch and understands analyzers, mappings and query tuning. The harder part is judgment: choosing between query-time prefix matching and index-time methods such as edge n-grams, search-as-you-type fields or completion suggesters, then testing how typo tolerance affects index size. A team new to search usually needs a few weeks of learning before it can make those calls with confidence. A partner adds the most value where the catalog is large, the languages are many or the latency target is strict.

What do we need to provide before the work starts?

Plan to provide:

  • A representative set of real user queries, including misspellings and partial words, from your search logs or site analytics
  • Read access to a sample of the documents or product records that autocomplete will suggest, and a way to refresh them
  • Your latency targets for suggestions, measured at the point users type
  • A named owner who can approve field choices, languages and ranking rules
  • A test environment that matches the production cluster's node roles and sizing
How long does a pilot usually take?

A pilot's length depends on how many sources feed suggestions, how many languages you support and how quickly your team can review query samples and results. Teams with clean data and one language usually move faster than teams with several catalogs and locales. Ask for the schedule in the written scope, with milestones for data access, index design, a working prototype against your sample queries, and a latency test. DeployOpen agrees timelines in writing before work begins.

How do reindex cycles affect the effort and the running cost?

Index-time methods such as edge n-grams and completion suggesters store extra terms, so changing analyzers, adding a field or altering typo rules usually means reindexing the data. Query-time prefix matching avoids most reindexing but can cost more per query on large catalogs. Ask your team how often the catalog changes, how large a reindex would be and whether a rebuild can run without downtime. Those answers shape both the design and the operations plan.

Will typo tolerance make the index much larger?

It can. Fuzzy matching and n-gram variants increase the number of terms stored or the work done per query, depending on the method chosen. The effect grows with catalog size and the number of fields indexed for suggestions. Test with a copy of your real data and measure index size, heap use and query latency before choosing a design. Keep typo rules narrow at first, then widen them against measured results.

When does a partner help more than an internal team?

A partner helps most when several of these apply: a large or multi-language catalog, a tight latency target, a cluster that is shared with logging or other workloads, a compliance review of the search data, or a team with no recent search experience. A partner is also useful when you need the design documented and handed over, with tests you can rerun after upgrades. DeployOpen implements self-hosted OpenSearch in your own cloud accounts, data centers or air-gapped networks, and can work fixed-scope or under a retainer for ongoing tuning.

How DeployOpen scopes and delivers autocomplete work

Autocomplete work starts with a written scope, not a cluster change. Before any build, DeployOpen and your team agree in writing which fields will suggest, which method each one uses (query-time prefix matching, edge n-grams, search-as-you-type fields or completion suggesters), how many suggestions a user sees, which languages and data sources are in play, and how success will be checked. The scope also names the deliverables, such as index mappings and analyzer definitions, query templates, a tested index-size estimate, a load test result and the runbook for reindexing. Timelines follow from that written scope, so a change in method or data volume is a scope change that both sides sign off before it affects the schedule.

The build happens in your OpenSearch environment, whether that runs in your cloud account, a data center or an air-gapped network. Index templates, custom analyzers, role mappings for the Security plugin and any suggest-only index aliases are created and tested against a non-production cluster first, then promoted through your own change process. This keeps the index size, memory use and any access rules visible to your platform and security teams from the start. Confirm with your team who owns cluster sizing, who approves index changes, and whether suggestion queries will be logged, since that affects both privacy review and storage planning.

After launch, tuning rarely stops. Suggestion quality shifts as catalogs change, typo tolerance interacts with new analyzers, and OpenSearch itself moves through minor and major releases. DeployOpen offers retainers for ongoing relevance tuning, upgrade testing and cluster care, which can be scoped separately from the original build. Ask any provider to state in the quote which items recur (hosting, support hours, upgrade testing) and which are one-time (initial design, index build, load testing), and to name what would trigger a new fixed-scope agreement.

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.