Most applications don't need Elasticsearch. PostgreSQL's built-in search — tsvector for full-text, pg_trgm for fuzzy matching — handles millions of records with good relevance and zero operational overhead. Add Elasticsearch when you need search relevance tuning across 10M+ documents, real-time log analytics at scale, or features like highlighting and percolation that PostgreSQL simply doesn't have.
How do they compare at a glance?
| Elasticsearch | PostgreSQL | |
|---|---|---|
| Primary role | Distributed search and analytics engine | Relational database with search capabilities |
| Search quality | Superior — BM25 scoring, analyzers, tokenizers, fuzzy, multi-field, highlighting | Adequate — tsvector ranking, pg_trgm similarity, prefix matching |
| Log analytics | Built for it — ELK stack, 100K+ events/sec ingestion | Not designed for high-volume log ingestion |
| SQL support | ES|QL (new, limited), Query DSL (JSON, verbose) | Native SQL — the standard |
| JOINs | No real JOINs — nested docs, parent-child, denormalization | Native, fast, all join types |
| Scaling | Horizontal — sharding and replication built-in | Vertical — read replicas, Citus for horizontal |
| Operations | Complex — cluster management, shard tuning, mapping conflicts | Mature, well-understood, decades of tooling |
| Cost | Expensive — RAM-hungry, 3+ nodes for HA | Runs on minimal hardware |
| ACID transactions | No | Full support |
| Schema flexibility | Schema-on-write, dynamic mapping | Strict schema, JSONB for semi-structured |
The split is clear. Elasticsearch is a search and analytics engine that happens to store data. PostgreSQL is a database that happens to search. Everything else follows from that.
Do I need Elasticsearch, or is PostgreSQL search enough?
This is the question I get asked most. Here's the decision tree I use:
Do you need full-text search?
│
┌────────┴────────┐
│ No │ Yes
│ │
Use PostgreSQL How many searchable records?
(LIKE + indexes) │
┌──────────┴──────────┐
│ < 10M │ > 10M
│ │
Do you need advanced Elasticsearch
relevance tuning? (scale alone justifies it)
│
┌────────┴────────┐
│ No │ Yes
│ │
PostgreSQL tsvector Do you also need
+ pg_trgm log/event analytics?
(handles this well) │
┌───────────┴───────────┐
│ No │ Yes
│ │
Consider either. Elasticsearch
ES is better at search, (search + analytics
but PG is simpler. in one system)If you answered "no" at the top, you almost certainly don't need Elasticsearch. If you have fewer than 10 million searchable records and your relevance needs are straightforward, PostgreSQL handles it. Above that, Elasticsearch earns its operational cost.
Fastero
Connect your database. Ask questions. Get dashboards.
Postgres, BigQuery, Snowflake, and 10+ sources — live-connected, AI-powered, no dashboard builder learning curve.
Try free →How does search quality differ?
This is where Elasticsearch genuinely pulls ahead. Same search, both systems — finding articles matching "postgres performance tuning":
PostgreSQL (tsvector):
-- Create the search index
ALTER TABLE articles ADD COLUMN search_vector tsvector
GENERATED ALWAYS AS (
to_tsvector('english', coalesce(title, '') || ' ' || coalesce(body, ''))
) STORED;
CREATE INDEX idx_articles_search ON articles USING GIN(search_vector);
-- Search
SELECT title, ts_rank(search_vector, query) AS rank
FROM articles, to_tsquery('english', 'postgres & performance & tuning') AS query
WHERE search_vector @@ query
ORDER BY rank DESC
LIMIT 20;Elasticsearch (Query DSL):
GET /articles/_search
{
"query": {
"multi_match": {
"query": "postgres performance tuning",
"fields": ["title^3", "body", "tags^2"],
"type": "best_fields",
"fuzziness": "AUTO"
}
},
"highlight": {
"fields": { "body": {} }
},
"size": 20
}The PostgreSQL version works. It'll find relevant results, rank them reasonably, and perform well with a GIN index. But notice what Elasticsearch gives you out of the box: field boosting (title^3), automatic fuzziness (catches typos), multi-field search across different analyzers, and highlighted snippets in the response. Getting equivalent behavior from PostgreSQL means stacking ts_rank, similarity(), custom weighting functions, and ts_headline — all doable, but you're rebuilding a search engine piece by piece.
For a product search box or site search? PostgreSQL is fine. For a search experience where relevance quality is the product — think documentation search, marketplace listings, or support ticket search across millions of records — Elasticsearch is meaningfully better.
What about log and event analytics?
This is Elasticsearch's home turf, not a close comparison. The ELK stack (Elasticsearch, Logstash, Kibana) ingests and indexes 100,000+ events per second on modest hardware. Kubernetes logs, application events, security audit trails — Elasticsearch handles the volume, makes it searchable immediately, and Kibana gives you dashboards without writing a line of code.
PostgreSQL can store logs. But inserting 100K rows per second while maintaining indexes and MVCC overhead will bring a single-node PostgreSQL to its knees. Even with partitioning and minimal indexes, PostgreSQL tops out around 10-50K inserts/second before you start making trade-offs on durability or indexing. If you're centralizing logs from more than a handful of services, PostgreSQL isn't the right tool.
That said — if your "log analytics" is really "query a few million application events per month," PostgreSQL handles it. Not everything is Kubernetes-at-scale.
How does SQL support compare?
PostgreSQL speaks ANSI SQL natively. Subqueries, CTEs, window functions, full JOIN support, stored procedures. Every SQL tool connects to it. Every developer knows the syntax.
Elasticsearch was built around Query DSL — a JSON-based query language that's powerful but verbose. A simple aggregation that's one line of SQL becomes a nested JSON document. ES|QL, introduced in 8.11, brings SQL-like syntax to Elasticsearch, but it's still maturing. Many operations still require dropping back to Query DSL.
If your team thinks in SQL, Elasticsearch adds friction. If your team lives in Kibana and uses pre-built visualizations, SQL support matters less.
What about JOINs?
This is PostgreSQL's structural advantage. Relational data with foreign keys, normalized schemas, multi-table JOINs — that's what PostgreSQL was built for.
Elasticsearch has no real JOINs. You work around it with nested documents (embed child records inside parent documents), parent-child relationships (limited to a single index), or denormalization (flatten everything at index time). Each approach has trade-offs in query speed, index size, and update complexity.
If your data is relational — orders referencing customers referencing accounts — PostgreSQL is the right system. If your data is naturally document-shaped — log entries, product listings, content pages — Elasticsearch's document model fits without contortions.
How do they scale differently?
Elasticsearch was built to scale horizontally. You add nodes, shards distribute automatically, replicas provide redundancy. A 3-node cluster becomes a 10-node cluster without reshaping your data model. This is why it handles petabytes of log data across large organizations.
PostgreSQL scales vertically first — bigger machine, more RAM, faster disks. Read replicas handle read-heavy workloads. For true horizontal scaling, you need Citus (distributed PostgreSQL) or application-level sharding. It works, but it's not built-in.
For most applications, PostgreSQL's vertical scaling is sufficient. A well-tuned PostgreSQL instance on modern hardware handles tens of millions of records with fast search. Horizontal scaling matters when you're past that — hundreds of millions of documents, multi-tenant indexing, or globally distributed search.
What does each cost to run?
Both are open-source and free to self-host. The operational costs differ sharply.
| Self-hosted | Managed | |
|---|---|---|
| PostgreSQL | Free (OSS) | $15-50/mo small (RDS, Supabase, Neon); $200-1000/mo production |
| Elasticsearch | Free (OSS) | Elastic Cloud from ~$95/mo (1 node); production clusters $300-2000+/mo |
Elasticsearch is RAM-hungry. Each node wants 16-32GB of heap, and you need at least 3 nodes for high availability. A production cluster with reasonable performance starts around $300/month on Elastic Cloud. PostgreSQL runs its search features on the same instance you're already paying for — the marginal cost of tsvector and pg_trgm is essentially zero.
The cost equation flips when PostgreSQL search isn't enough. Running slow searches that frustrate users, or building custom relevance logic on top of PostgreSQL to avoid Elasticsearch, costs engineering time. If search quality is revenue-critical, Elasticsearch pays for itself.
When should you use PostgreSQL search?
PostgreSQL search covers more ground than people realize. Use it when:
- You have fewer than 10 million searchable records — GIN indexes keep tsvector queries under 100ms at this scale
- You need autocomplete —
pg_trgmwithsimilarity()andLIKEon a trigram index handles type-ahead search - You want one database — no separate search cluster to provision, monitor, and keep in sync
- Your search needs are feature search, not product search — a search box in an admin panel, a filter-as-you-type list, basic keyword matching
- You already use PostgreSQL and your search SLA is "works", not "best-in-class relevance"
A well-indexed PostgreSQL search handles the search needs of most SaaS applications, internal tools, and content sites below 10M records.
When do you need Elasticsearch?
Switch to Elasticsearch when:
- Search relevance is the product — marketplace search, documentation portals, support ticket search where ranking quality directly affects user experience
- You have more than 10 million searchable documents and need consistent sub-second response times
- You need real-time log or event analytics — centralized logging, application monitoring, security event analysis
- You need search features PostgreSQL can't replicate — percolation queries (reverse search), significant terms aggregation, geo-distance scoring, complex multi-field boosting
- You're already running Kibana dashboards and the ELK ecosystem fits your monitoring and observability stack
FAQ
Can I use PostgreSQL and Elasticsearch together?
Yes, and it's the most common pattern for applications that outgrow PostgreSQL search. PostgreSQL remains the source of truth — your application reads and writes there. Elasticsearch gets a copy of the searchable data (via Logstash, a CDC pipeline, or application-level dual writes) and serves the search API. This gives you PostgreSQL's transactional safety and Elasticsearch's search quality without forcing a choice.
Is pg_trgm good enough for fuzzy search?
For most applications, yes. pg_trgm computes trigram similarity and supports LIKE/ILIKE with index acceleration. It catches typos, handles partial matches, and runs fast on tables under 10 million rows. Where it falls short: multi-language analysis, phonetic matching, and fine-grained relevance tuning. If "good enough fuzzy search" meets your needs, pg_trgm saves you from running Elasticsearch.
How hard is it to keep Elasticsearch in sync with PostgreSQL?
This is the biggest operational headache. Every write to PostgreSQL must propagate to Elasticsearch, or search results go stale. Options range from simple (application dual-writes — fragile, risk of drift) to reliable (Debezium CDC streaming changes from the PostgreSQL WAL — consistent, but more infrastructure). Budget for the sync pipeline when evaluating Elasticsearch's total cost. For analytics across both systems, a tool that connects to both directly avoids the sync problem entirely.
Should I use OpenSearch instead of Elasticsearch?
OpenSearch is the AWS-maintained fork of Elasticsearch 7.10. The APIs are nearly identical, and most tooling works with both. Choose OpenSearch if you're on AWS (managed via OpenSearch Service), if you prefer the Apache 2.0 license, or if you want to avoid Elastic's licensing changes. Choose Elasticsearch if you need the latest features (ES|QL, vector search improvements) or want Elastic Cloud's managed experience. For PostgreSQL-vs-search-engine comparisons, everything in this post applies to both.
What about Typesense or Meilisearch as alternatives?
Both are purpose-built search engines that are simpler to operate than Elasticsearch. Typesense is fast, has good typo tolerance, and works well for product search under 100M records. Meilisearch offers a great developer experience with sensible defaults. Neither handles log analytics. If your need is strictly application search (not log analytics, not event indexing), they're worth evaluating — lighter than Elasticsearch, better search than PostgreSQL.
Related posts:
- PostgreSQL vs MySQL for Analytics
- DuckDB vs PostgreSQL for Analytics Workloads
- ClickHouse vs PostgreSQL for Analytics
- Best Tools for Data Engineering Teams (2026)
Try Fastero free — analytics dashboards on PostgreSQL, Elasticsearch, or both. Connect your data, ask questions in SQL or English. No credit card required.

