r/javascript • u/delightfullyrotted js • Aug 01 '26
AskJS [AskJS] how are you handling autocomplete on top of elasticsearch?
elasticsearch is pretty great when given a full query, but i find most people just search one or two words. so feels like helping ppl know what to search for is the actual thing that’s needed. so now im looking for solid ways to add ai-autocomplete upfront without replacing our elasticsearch backend (not looking to switch backend like algolia since pricing gets stupid fast)
i've been looking into a few different directions. typesense and meilisearch seem cool if you want a lightweight search engine replacement, but again that doesnt feel like the real root cause issue. so we're looking at putting an ai-autocomplete layer directly in the UI text box to capture user intent before hitting elasticsearch
has anyone else done this? do you tune elasticsearch queries on the backend or add an intent layer upfront to collect parameters before the query runs?
1
u/PBzCharlie Aug 01 '26
depends on what your product managers are actually pushing for, half the time devs stress over massive backend search engines when the business side just wants a pretty UI drop-down that feels fast
1
u/pdfops Aug 01 '26
We did this with ES's completion suggester instead of bolting on a separate service. Index past popular queries plus titles into a dedicated suggest field (FST-based, sub-ms lookups), weight by click-through or frequency. Covers most of what people actually type. Only reach for an embedding/AI layer when you need semantic intent past typo-tolerant prefix match, that's where latency and infra cost jump.
1
u/J_be Aug 02 '26
Don't ditch Elasticsearch (ES); just add an Intent Layer upfront. Backend tuning alone won't bridge the "vocabulary gap" of 2-word queries.
1. Frontend: Intent Middleware
Use a small, fast LLM (like gpt-4o-mini) to transform fragments into structured parameters before hitting the DB.
{"color": "red", "intent": "browse_category"}.2. Backend: HyDE (Hypothetical Document Embeddings)
Use the ES v8.x Inference API to solve the short-query problem semantically.
The Hybrid Pipeline (The "Algolia-Killer")
ES Query: Run a
boolquery combining:This architecture keeps your data in ES, avoids Algolia’s per-operation tax, and makes "lazy" searches significantly more accurate.
0
u/r0ek22 Aug 01 '26
half the time devs stress over massive backend scaling when the users just want a pretty dropdown that feels fast
0
u/[deleted] Aug 01 '26
[deleted] — view deleted comment
4
u/[deleted] Aug 01 '26
[removed] — view removed comment