ClickHouse vs. Elasticsearch: The Mechanics of Count Aggregations
ClickHouse runs count(*) GROUP BY aggregations in parallel at three levels: SIMD within column values, multiple cores over arbitrary data ranges, and multiple nodes over shards. Partial aggregation states let the results be merged exactly. Elasticsearch's terms aggregation instead uses one thread per shard and merges shard-local top-n results. That approach gives approximate counts across shards unless shard_size is raised, always requires a size limit, and is capped by max_buckets. For continuous summarization, ClickHouse's -State/-Merge combinators with AggregatingMergeTree and materialized views aggregate incrementally during background merges. Elasticsearch transforms must keep raw data and re-aggregate whole buckets on every checkpoint, so they are not real-time.
Related posts
- ClickHouse vs. Elasticsearch: The Billion-Row Matchup
ClickHouse mediumAdept
On a single 32-core c6a.8xlarge node loaded with 1, 10 and 100 billion PyPI download rows, ClickHouse beats Elasticsearch on count(*) GROUP BY aggregations (Elasticsearch terms aggregations). ClickHouse needs 12–19x less storage and delivers at least 5x lower query latency, so roughly 4x cheaper hardware matches Elasticsearch's latency. Its materialized views are also cheaper in storage and compute than Elasticsearch transforms for continuous summarization. The setup details cover ILM rollover, index sorting by cardinality, LZ4 vs DEFLATE/ZSTD codecs, _source tradeoffs and shard parallelism, and note that Elasticsearch could not ingest the 100B-row dataset.
- Why ClickHouse Cloud wins at real-time analytics
ClickHouse mediumAdept
In the CostBench streaming benchmark (113.2 billion stock quotes ingested at about 1M rows/s while queries ran), ClickHouse Cloud scored 412× to 1,996× better end-to-end performance per dollar than Snowflake, Databricks, BigQuery and Redshift Serverless. Its lead comes from sorting data and computing incremental materialized-view pre-aggregations in memory at insert time, so summaries never lag behind raw data. Background part merges then keep combining the mergeable aggregation states. Ingestion and merging are parallelized across nodes, cores and SIMD lanes, and a 4-core ingest service prepared all the data for $28.69 with 14.4× compression, while the other systems needed separate asynchronous refresh stages that lagged and cost $79–$696.
- Using Materialized Views in ClickHouse
ClickHouse mediumAdept
ClickHouse materialized views act as insert-time triggers that write the result of a SELECT into a target table, letting expensive aggregations be precomputed. On a 1B-row Wikistat dataset, a SummingMergeTree-backed view cuts a top-projects query from 15 seconds to 3 ms, and AggregatingMergeTree with *State()/*Merge() combinators handles min/max/avg the same way. The same mechanism supports compacting history (with source-table TTL), validating and filtering rows via a Null-engine source table, routing invalid data to separate tables, and transforming columns. Practical guidance: keep views per table to around ten or fewer, still GROUP BY at query time since merges are asynchronous, avoid FINAL on large tables, and only aggregate for storage when it reduces rows by roughly 10x.
- ClickHouse Release 25.11
ClickHouse mediumAdept
ClickHouse 25.11 ships 24 features, 27 performance optimizations and 97 bug fixes. Headline additions are automatic TLS certificate provisioning via ACME (Let's Encrypt, ZeroSSL), with certificates shared across the cluster through ClickHouse Keeper, and parallel merging for GROUP BY on 8/16-bit keys. That merge works because FixedHashMap is a directly indexed array, so merge threads can each take disjoint, interleaved key positions without locks, giving about a 40% speedup on a uniqExact benchmark. Lightweight _part_offset projections now prune at granule level and act as secondary indexes, cutting a two-filter query by 90%. DISTINCT queries can also read from smaller pre-aggregated projections when those contain the distinct key.
- How Rokt Achieved Real-time Reporting with ClickHouse
ClickHouse easyNovice
Rokt replaced an Elasticsearch-backed reporting layer with ClickHouse. Elasticsearch lacked flexible group-by and filtering, had no S3 loading or joins, required JSON queries, and forced full re-ingestion whenever a label changed. After ruling out Pinot, Druid, Snowflake, StarRocks and Citus, the team benchmarked ClickHouse against Redshift: ClickHouse was about 3x cheaper, handled up to 200 queries per second with a maximum query time of six seconds, and stored 500 GB of gzipped Parquet in roughly the same space, about one sixth of the Elasticsearch footprint. The current self-managed setup runs ClickHouse in an autoscaling group with ZooKeeper behind network load balancers, and Rokt plans to move to ClickHouse Cloud to offload replication, sharding and backups.