Prompt
I'm building search on top of Postgres — what stack should I use?
Latest observation
Oct 12, 2026
OpenAI APIWeb search: off
It depends on what “search” means for your app, but if you’re building on top of Postgres, the usual best answer is:
Good default stack
- Postgres as the source of truth
- Postgres Full-Text Search for basic text search
- pg_trgm for fuzzy matching / typo tolerance
- A small search service layer in your app for ranking, filtering, and query building
- Redis only if you need caching or fast autocomplete suggestions
- OpenSearch/Elasticsearch only if your search needs grow beyond what Postgres can comfortably handle
When Postgres is enough
Use Postgres search if you need:
- keyword search
- filtering by structured fields
- moderate scale
- simple relevance ranking
- search tightly coupled with transactional data
Typical features:
tsvector/tsquery- GIN indexes
pg_trgmfor%term%-style matching and fuzzy search- optional materialized views or generated columns for precomputed search vectors
This is the best starting point for most apps.
When to add a dedicated search engine
Consider OpenSearch/Elasticsearch if you need:
- advanced relevance tuning
- faceting/aggregations at large scale
- complex synonyms, stemming, language analysis
- autocomplete at very high QPS
- huge datasets with heavy read load
- near-real-time indexing/search at scale
Recommended architecture
Simple version
- App writes to Postgres
- Search queries hit Postgres directly
- Use:
tsvectorcolumns- GIN index
pg_trgmon searchable text fields
Scalable version
- Postgres is primary DB
- CDC or background jobs sync data to search index
- Search layer (Postgres or OpenSearch) powers queries
- App talks to a search API, not directly to SQL
Practical stack recommendation by stage
MVP / early stage
- Postgres +
tsvector+pg_trgm - Query builder in your app
- Redis for caching if needed
Growth stage
- Postgres search still primary
- Add background indexing jobs
- Add autocomplete with Redis or a materialized suggestions table
Large scale / complex relevance
- Postgres as source of truth
- OpenSearch for search
- CDC via Debezium / logical replication / app events
My opinionated recommendation
Start with:
- Postgres FTS
- pg_trgm
- GIN indexes
- application-side ranking/filters
- background indexing jobs
Only move to Elasticsearch/OpenSearch when you can clearly name the limitation you’ve hit.
If you want, I can also give you:
- a concrete Postgres schema + index setup,
- a recommendation by use case (product search, docs search, people search, etc.), or
- a decision tree for Postgres vs OpenSearch.