Elasticsearch vector search turns the search engine many teams already run into a vector database. It stores embeddings in dense_vector fields, retrieves the most similar vectors with k-nearest neighbour (kNN) search, and combines that with full-text search, filters and aggregations in one engine. The central question is whether it can replace a dedicated vector store, and the honest answer is yes for most teams that already run Elasticsearch, especially when hybrid retrieval matters more than raw vector scale.
This guide explains how vector search works in Elasticsearch, how to set it up, where it excels and where a specialist store still wins. For the broader choice between engines and vector stores, see our vector database vs search engine comparison.
Key takeaways
- Elasticsearch stores embeddings in dense_vector fields and queries them with kNN search, added in version 8.0.
- Vector search combines with BM25 full-text search, filters and aggregations in a single query, which makes hybrid retrieval native.
- The semantic_text field type handles chunking and embedding automatically, while dense_vector gives full control.
- It is the strongest choice when you already run Elasticsearch; a dedicated vector store suits vector-only workloads at extreme scale.
How Elasticsearch Vector Search Works
Vector search in Elasticsearch starts with embeddings, which are numerical lists produced by a machine learning model from text, images or other data. A dense_vector field stores one embedding per document, and a kNN query finds the k nearest vectors to a query vector as measured by a similarity metric. Approximate kNN uses an HNSW graph, the same algorithm behind most dedicated vector stores, while exact search is available through script scoring for smaller collections.
To run approximate kNN, you map a dense_vector field with indexing enabled and a similarity value, such as cosine, dot product or L2 norm. The query then specifies the field, the query vector, the number of results k, and how many candidates to consider per shard. Elasticsearch also supports byte vectors alongside float vectors, which halves the storage for quantized embeddings.
There are two ways to query: the Query DSL, which is the JSON request body of the search API, and ES|QL, the piped query language, which exposes a KNN function plus vector similarity functions such as V_COSINE and V_DOT_PRODUCT. The official documentation describes both paths in the k-nearest neighbour search guide.
Best for: teams that already run Elasticsearch and want semantic search without adding a second retrieval system.
Field Types: dense_vector, sparse_vector and semantic_text
Elasticsearch offers three field types for vector work, and picking the right one shapes everything else. The dense_vector type stores embeddings you generate yourself, which gives full control over the model, the dimension and the indexing settings. It is the right choice when you already have an embedding pipeline.
The sparse_vector type stores sparse vectors, typically generated by ELSER, the Elastic Learned Sparse Encoder model, which expands text into weighted terms. Sparse retrieval behaves like learned keyword search and pairs well with dense vectors in hybrid queries.
The semantic_text field type is the easiest starting point. It handles chunking and embedding automatically using an inference service, so you can index plain text and search it semantically without managing vectors at all. Use it when you want working semantic search quickly, and move to dense_vector when you need control over the model or the indexing parameters.
Hybrid Search: The Real Advantage
Most searches do not rely on vectors alone. Lexical search is strong for exact terms, product codes and names, while vectors are strong for meaning and paraphrase. Elasticsearch combines the two natively: a single search request can carry both a kNN clause and a full-text query, fused through reciprocal rank fusion (RRF).
This matters because hybrid retrieval usually beats either method alone on real document collections. Keyword search catches the exact phrase, vector search catches the same idea worded differently, and fusion produces a ranking that benefits from both. Our hybrid search for RAG guide explains why this combination improves retrieval quality.
Filters add another layer. A kNN query accepts prefilters, so you can limit candidates to one tenant, one category or one date range before the vector search runs. Aggregations then work on the same result set, which means you can build faceted search, analytics dashboards and semantic search on the same index without moving data between systems.
Best for: search products that need keyword, semantic and filtered retrieval in one place, with analytics on top.

Elasticsearch Vector Search vs Dedicated Vector Databases
| Feature | Elasticsearch | Dedicated vector database |
|---|---|---|
| Vector index | HNSW on dense_vector fields | HNSW, often with quantization |
| Full-text search | Native BM25, mature and fast | Basic or via sparse vectors |
| Hybrid retrieval | kNN plus query, fused with RRF | Dense plus sparse, RRF fusion |
| Filtering | Prefilters in the kNN clause | Payload or metadata indexes |
| Aggregations | Full aggregation framework | Limited or absent |
| Embedding generation | Inference endpoints and semantic_text | Usually bring your own model |
| Scale comfort zone | Large, as a distributed search engine | Very large, vector-only workloads |
| Operations | One engine for search and vectors | One more system to run |
Setting Up Vector Search
A basic setup has four steps. First, choose an embedding model and fix the dimension, since changing it later means re-indexing. Second, create an index with a dense_vector mapping that sets the dimension, enables indexing and picks a similarity metric. Third, index documents with their embeddings, ideally in batches for speed. Fourth, run a kNN query with a sensible k and num_candidates, and check recall on real questions before tuning.
Two settings deserve attention early. The similarity metric must match your embedding model: cosine is the usual choice for text embeddings, while dot product suits models trained for it. The num_candidates value controls how many candidates each shard considers, and raising it improves recall at the cost of latency, so it is the main dial for the speed-quality trade-off.
For retrieval-augmented generation, the pattern is familiar: chunk documents, embed the chunks, store them with metadata, and retrieve the top matches to ground the language model’s answer. Because the same index holds the text, the vectors and the metadata, the retrieval step and the filtering step stay in one query. Our best vector databases for RAG guide compares this setup with the alternatives.
When Elasticsearch Is the Right Choice
Elasticsearch is the right choice when search is already a core part of your product. If you run it for logs, product search or site search, adding vector search reuses the cluster, the operational knowledge and the security model you already have. That reuse is worth more than a small edge in vector-only benchmarks.
It is also the right choice when your queries mix signals. A support search that needs keyword matching on error codes, semantic matching on problem descriptions and aggregations for analytics is a natural Elasticsearch workload. The same applies to e-commerce search, where filters, facets and ranking rules matter as much as similarity. Our vector search vs full-text search guide helps you decide how to weight each signal.
The trade-off is operational weight. Elasticsearch is a distributed system with real tuning and capacity planning, and a small team may find a managed vector database simpler for a vector-only workload. It is also heavier than a lightweight store for a prototype, so starting small and growing into it is usually the sensible path.
Decision Checklist: Is Elasticsearch Vector Search Right for You?
- Do you already run Elasticsearch? If yes, vector search is a feature to switch on, not a new system to adopt.
- Do you need keyword and vector search together? If yes, native hybrid retrieval is a strong reason to choose Elasticsearch.
- Do you need aggregations and analytics? If yes, the aggregation framework is a capability most vector stores lack.
- Is vector search your only retrieval need? If yes, a dedicated vector database may be lighter and cheaper.
- Can your team operate a cluster? If not, consider a managed Elasticsearch service or a managed vector database.
- Have you fixed your embedding model? Changing models means re-indexing, so validate retrieval quality on a small collection first.
- Do you need inference inside the engine? The semantic_text field and inference endpoints remove the need for a separate embedding service.
Common Mistakes to Avoid
The most common mistake is choosing the wrong similarity metric for the embedding model, which silently degrades ranking. Check what your model was trained for and match the mapping to it. The second mistake is skipping prefilters and filtering after retrieval instead, which wastes candidates on documents that can never match.
A third mistake is treating k and num_candidates as set-and-forget values. Start with modest numbers, measure recall against a set of real questions with known answers, and raise num_candidates only until recall stops improving. A fourth mistake is indexing vectors without a plan for updates: when documents change, their embeddings must change too, or the index quietly goes stale.
Frequently Asked Questions
Can Elasticsearch be used as a vector database?
Yes. Elasticsearch functions as a vector database when you store embeddings in dense_vector or sparse_vector fields and query them for similarity, and it combines that with full-text search, filters and aggregations in one engine.
When was kNN search added to Elasticsearch?
Support for approximate kNN search was added in version 8.0. Earlier versions offered only exact search through script scoring, which is slower on large collections.
What is the difference between dense_vector and semantic_text?
dense_vector stores embeddings you generate yourself and gives full control over the model and indexing. semantic_text handles chunking and embedding automatically through an inference service, so you index plain text and search semantically with less setup.
Does Elasticsearch support hybrid search?
Yes. A search request can combine a kNN clause with a full-text query, and the results are fused with reciprocal rank fusion, so keyword and semantic signals contribute to the final ranking.
Is Elasticsearch vector search fast enough for production?
Yes, for most workloads. Approximate kNN on HNSW graphs serves typical queries in tens of milliseconds, and the main tuning dial is num_candidates, which trades latency for recall.
Should I choose Elasticsearch or a dedicated vector database for RAG?
Choose Elasticsearch if you already run it or need hybrid search, filtering and analytics in one engine. Choose a dedicated vector database if vector search is your only retrieval need and you want the lightest possible setup.







