Prompt
How do I migrate from Elasticsearch to vector search?
Latest observation
Migrating from Elasticsearch to vector search usually means moving from keyword/full-text retrieval to semantic retrieval using embeddings. In practice, many teams keep Elasticsearch for lexical search and add a vector database or vector index for semantic search, then blend the two.
Here’s a practical migration path.
1) Decide what “vector search” is replacing
First, identify your use case:
- Semantic document search: “Find docs about payment failures” even if those exact words aren’t present.
- Similarity search: “Find items like this product / ticket / paragraph.”
- RAG retrieval: fetch relevant chunks for an LLM.
- Hybrid search: combine keyword + semantic ranking.
If your current Elasticsearch setup depends on:
- exact term matching,
- filters/facets,
- boolean queries,
- aggregations,
then vector search is usually not a full replacement. It’s often an additional retrieval layer.
2) Choose a target architecture
Common options:
Option A: Elasticsearch with vector support
If you already use Elasticsearch, the easiest path may be to use:
dense_vector- kNN / approximate nearest neighbor search
- hybrid scoring with BM25 + vector similarity
This minimizes operational change.
Option B: Dedicated vector database
Examples:
- Pinecone
- Weaviate
- Milvus
- Qdrant
- pgvector (Postgres)
- OpenSearch vector search
Best if semantic retrieval is central and you want specialized indexing/query behavior.
Option C: Hybrid architecture
- Elasticsearch for keyword search, filters, aggregations
- Vector DB for semantic similarity
- Merge/rerank results in your app
Best for production search experiences.
3) Define your embedding strategy
Vector search requires converting text into embeddings.
Questions to answer:
- What model will generate embeddings?
- OpenAI, Cohere, Voyage, Sentence Transformers, etc.
- What unit do you embed?
- whole documents
- paragraphs
- chunks of 200–500 tokens
- What dimension size?
- depends on the model
- Do you need multilingual embeddings?
Important:
For long documents, chunking is usually necessary. Search works better on semantically coherent chunks than on entire large docs.
4) Restructure your data model
Elasticsearch documents often contain:
- full text
- metadata
- nested fields
- analyzers
- aggregatable fields
Vector search documents usually look like:
idembedding(vector)textorchunk_textmetadata(source, date, author, tags, ACLs)- optional sparse/keyword fields for filtering
Example:
{
"id": "doc_123_chunk_4",
"text": "To reset your password, go to ...",
"embedding": [0.012, -0.84, ...],
"metadata": {
"doc_id": "doc_123",
"chunk_index": 4,
"source": "help_center",
"language": "en"
}
}
5) Build an ingestion pipeline
Migration is mostly an indexing problem.
Pipeline:
- Export documents from Elasticsearch
- Clean and normalize text
- Split into chunks
- Generate embeddings
- Store vectors + metadata in the new system
- Keep IDs stable for updates/deletes
Tips:
- Use the original Elasticsearch
_idas a stable reference. - Store
doc_idandchunk_idseparately. - Track versioning so you can re-embed content when text changes.
- Make reindexing idempotent.
6) Recreate filtering and access control
Vector search is good at similarity, but most production search needs structured constraints:
- language
- tenant
- document type
- time range
- permissions / ACLs
Make sure your vector system supports:
- metadata filtering
- post-filtering
- pre-filtering
- namespace/partitioning
If you have row-level security or ACLs, design that early.
7) Plan your query strategy
Vector search is usually not one query type; it’s a ranking strategy.
Common query flow:
- Embed the user query
- Retrieve top-k nearest chunks
- Apply metadata filters
- Optionally combine with BM25/keyword results
- Optionally rerank with a cross-encoder or LLM reranker
Hybrid retrieval is often best:
- lexical search helps with exact names, IDs, error codes
- vector search helps with intent and paraphrase matching
8) Evaluate before cutting over
Don’t migrate blindly.
Build an evaluation set:
- 50–500 real queries
- human-labeled relevant docs/chunks
- measure:
- recall@k
- precision@k
- MRR / nDCG
- latency
- cost
Compare:
- Elasticsearch-only
- vector-only
- hybrid
In many cases, hybrid wins.
9) Run in parallel
A safe migration strategy:
Phase 1: Dual-write
Write new/changed content to:
- Elasticsearch
- vector index
Phase 2: Shadow queries
Send queries to the vector system in the background and compare results.
Phase 3: Hybrid production
Use vector search for ranking or fallback while keeping Elasticsearch live.
Phase 4: Gradual cutover
Switch traffic by percentage or use-case.
10) Handle updates, deletes, and freshness
This is a common gotcha.
You need:
- delete vectors when source docs are deleted
- re-embed when content changes
- handle partial updates carefully
- maintain sync between source of truth and search stores
A good pattern is:
- source of truth in your app DB or document store
- search indexes are derived artifacts
- use events/CDC to update both Elasticsearch and vector index
11) What you lose vs Elasticsearch
Vector search does not naturally replace:
- complex aggregations
- exact phrase/term queries
- faceting at scale
- rich boolean query DSL
- advanced text analyzers
If you rely heavily on those, keep Elasticsearch for that part.
12) Typical migration patterns
Pattern 1: Add semantic search to existing Elasticsearch
- Keep Elasticsearch
- Add embeddings fields or vector index
- Hybrid queries
- Lowest migration risk
Pattern 2: Split responsibilities
- Elasticsearch = filters, aggregations, keyword search
- Vector DB = semantic retrieval
- App merges results
Pattern 3: Full move for RAG
- Store chunks + embeddings in vector DB
- Only metadata and source docs in relational DB or object storage
- Elasticsearch retired or minimized
13) Simple migration checklist
- Define search use cases
- Pick embedding model
- Decide document vs chunk granularity
- Choose vector store or Elasticsearch vector support
- Design schema with metadata filters
- Build embedding + indexing pipeline
- Set up dual-write
- Create evaluation dataset
- Compare lexical vs semantic vs hybrid
- Add reranking if needed
- Run shadow traffic
- Gradually cut over
14) Recommended practical approach
If you’re unsure, start with:
- Keep Elasticsearch
- Add embeddings for chunks
- Use hybrid retrieval
- Measure search quality
- Only replace components that clearly benefit
That’s usually the safest and most effective migration path.
If you want, I can also give you:
- a step-by-step migration plan for your specific stack,
- an Elasticsearch → vector DB schema mapping,
- or a Python example for dual indexing and hybrid retrieval.