Elasticsearch Autocomplete Setup (Completion Suggester)

A user waiting 200 ms for an autocomplete response kills UX. In one electronics e-commerce project, every typed character triggered a full-text search query against the database. Server load increased, speed dropped, and customers left. The solution — Elasticsearch Completion Suggester. This mechani

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1419
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1287
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    983
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1244
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    983
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    998

A user waiting 200 ms for an autocomplete response kills UX. In one electronics e-commerce project, every typed character triggered a full-text search query against the database. Server load increased, speed dropped, and customers left. The solution — Elasticsearch Completion Suggester. This mechanism, based on FST (Finite State Transducer), stores data in memory and returns responses in 1–5 ms. We have implemented it in over 50 projects over 10+ years and guarantee stable performance under load.

This guide covers Elasticsearch autocomplete setup using Completion Suggester, comparing it with Edge N-gram. How it works: you type "no" — the system returns "notebook", "socks", "november" without delay. The suggester uses a completion field containing an input array (autocomplete options) and an optional weight (priority). For popular products, the weight is set based on sales or clicks.

How to Implement Completion Suggester for Autocomplete?

Step 1: Define the Mapping

Completion Suggester is the fastest option but less flexible: no full-text scoring, limited filtering. Mapping for completion field:

PUT /products { "mappings": { "properties": { "title": { "type": "text" }, "suggest": { "type": "completion", "analyzer": "simple", "search_analyzer": "simple", "preserve_separators": true, "preserve_position_increments": true, "max_input_length": 50 } } } } 

Step 2: Index Documents with Weights

Indexing a document with weight (e.g., higher for popular products):

PUT /products/_doc/1 { "title": "Ноутбук ASUS VivoBook 15", "suggest": { "input": ["Ноутбук ASUS VivoBook", "ASUS VivoBook 15", "VivoBook"], "weight": 10 } } 

Step 3: Query with Fuzzy and Duplicate Skipping

Autocomplete query with fuzzy:

POST /products/_search { "suggest": { "product-suggest": { "prefix": "ноут", "completion": { "field": "suggest", "size": 5, "skip_duplicates": true, "fuzzy": { "fuzziness": 1 } } } }, "_source": ["title", "price"], "size": 0 } 

The response returns options with _source fields. Response time — 1–5 ms.

Choosing Between Completion Suggester and Edge N-gram

The choice depends on priority: speed vs. flexibility. The suggester is 10x faster than N-gram under the same load — confirmed by our load tests. If your data is static (product catalog, city list) and maximum speed is needed — choose it. If full-text search with filtering and sorting is required — Edge N-gram.

What is Context Suggester and How to Use It?

Context Suggester extends the completion mechanism with filtering by context — for example, by product category. Mapping with context:

PUT /products { "mappings": { "properties": { "suggest": { "type": "completion", "contexts": [ { "name": "category", "type": "category", "path": "category" } ] }, "category": { "type": "keyword" } } } } 

Indexing with context:

PUT /products/_doc/1 { "title": "Ноутбук ASUS", "category": "laptops", "suggest": { "input": ["Ноутбук ASUS", "ASUS"], "contexts": { "category": ["laptops"] } } } 

Query with context and boost:

POST /products/_search { "suggest": { "product-suggest": { "prefix": "ас", "completion": { "field": "suggest", "size": 5, "contexts": { "category": [ { "context": "laptops", "boost": 2 }, { "context": "tablets" } ] } } } } } 

Context Suggester increases relevance: if the user is in the "Laptops" section, suggestions show only laptops. In one project, we achieved a 30% increase in suggestion click-through rate due to accuracy.

What are the Limitations of Completion Suggester?

Edge N-gram: Alternative with Full-Text Search

Edge N-gram indexes partial tokens (minimum length 2 characters) and uses standard match query with full TF/IDF scoring, filtering, and sorting. Example mapping:

PUT /products { "settings": { "analysis": { "tokenizer": { "edge_ngram_tokenizer": { "type": "edge_ngram", "min_gram": 2, "max_gram": 20, "token_chars": ["letter", "digit"] } }, "analyzer": { "autocomplete_index": { "type": "custom", "tokenizer": "edge_ngram_tokenizer", "filter": ["lowercase"] }, "autocomplete_search": { "type": "custom", "tokenizer": "standard", "filter": ["lowercase"] } } } }, "mappings": { "properties": { "title": { "type": "text", "analyzer": "autocomplete_index", "search_analyzer": "autocomplete_search" } } } } 

Query:

POST /products/_search { "query": { "match": { "title": { "query": "ноут", "operator": "and" } } }, "sort": [{ "_score": "desc" }], "size": 5 } 
Feature Completion Suggester Edge N-gram
Response speed 1–5 ms 10–50 ms
Query flexibility Limited (prefix) Full (match, filtering, sorting)
Memory usage High (FST) Medium (inverted index)
Typo support Built-in fuzzy Requires separate analyzer
Best use case Static data with weights Dynamic data with full-text search

Typical Autocomplete Setup Mistakes

  • Forgetting skip_duplicates: without it, duplicate options may appear.
  • Not setting max_input_length — default is 50, may be insufficient for long names.
  • Using size: 0 in the main query but forgetting _source — extra fields are returned.
  • Not configuring debounce on the frontend: sending a request on every character creates a request avalanche. We recommend a 200–300 ms delay and caching previous results.

Server-Side Implementation Example

Example in PHP using elasticsearch-php:

public function autocomplete(string $query): array { $response = $this->client->search([ 'index' => 'products', 'body' => [ 'suggest' => [ 'product-suggest' => [ 'prefix' => mb_strtolower($query), 'completion' => [ 'field' => 'suggest', 'size' => 8, 'skip_duplicates' => true, 'fuzzy' => ['fuzziness' => 'AUTO'], ] ] ], '_source' => ['title', 'slug', 'price'], 'size' => 0, ] ]); return array_map(fn($opt) => [ 'title' => $opt['text'], 'price' => $opt['_source']['price'], ], $response['suggest']['product-suggest'][0]['options'] ?? []); } 

On the frontend, be sure to add a 200–300 ms debounce and cache previous results to avoid overloading the server.

What's Included in Our Autocomplete Solution

Our complete autocomplete implementation package includes:

  • Requirements analysis and selection of optimal mechanism (Completion Suggester vs Edge N-gram)
  • Mapping design and index configuration
  • API endpoint implementation with fuzzy and context support
  • Frontend integration (debounce, caching)
  • Full documentation and code repository access
  • Training session for your developers
  • One month post-deployment support
  • Response time guarantee of under 5 ms

Pricing: Basic Completion Suggester setup starts at $500. A full solution with Context Suggester and Edge N-gram ranges from $1,000 to $2,000, depending on complexity. Typical savings from reduced server load and improved conversion rates can exceed $5,000 per month for high-traffic e-commerce sites.

Timeline: We can set up a basic autocomplete in 1 day. Adding Context Suggester takes another half day. Full Edge N-gram integration with all features requires 1–2 days. Contact us for a free project assessment—we'll estimate your exact needs and provide a fixed price.

Elasticsearch official documentation recommends using Completion Suggester for high-speed autocomplete scenarios.