---
title: "ClickHouse vs. Elasticsearch: The Mechanics of Count Aggregations"
description: "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."
url: "https://swe.quest/articles/clickhouse-vs-elasticsearch-the-mechanics-of-count-aggregations-fa943a94e2c565e4"
canonical: "https://clickhouse.com/blog/clickhouse_vs_elasticsearch_mechanics_of_count_aggregations"
source: "ClickHouse"
published: "2024-05-07"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 15
tags: ["query-engines","analytics","search","performance"]
---

# ClickHouse vs. Elasticsearch: The Mechanics of Count Aggregations

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2024-05-07, 15 min read, Deep dive. Original: [https://clickhouse.com/blog/clickhouse\_vs\_elasticsearch\_mechanics\_of\_count\_aggregations](https://clickhouse.com/blog/clickhouse_vs_elasticsearch_mechanics_of_count_aggregations)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [Search](https://swe.quest/tags/search.md) (Backend & APIs)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- SQL GROUP BY aggregation ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- Elasticsearch aggregations ([easy posts on Search](https://swe.quest/tags/search.md?difficulty=easy))
- database sharding ([easy posts on Databases](https://swe.quest/tags/databases.md?difficulty=easy))

## Keywords

ClickHouse, Elasticsearch, terms aggregation, AggregatingMergeTree, materialized views, Elasticsearch transforms, SIMD

## Related posts

- [ClickHouse vs. Elasticsearch: The Billion-Row Matchup](https://swe.quest/articles/clickhouse-vs-elasticsearch-the-billion-row-matchup-227267b2f21c24e1.md): ClickHouse · 2024-05-07 · Medium · 28 min read · Analytics & OLAP, Performance engineering, Search, Databases, Observability
  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).
- [Why ClickHouse Cloud wins at real-time analytics](https://swe.quest/articles/why-clickhouse-cloud-wins-at-real-time-analytics-ff3bf2806ccb7be7.md): ClickHouse · 2026-10-28 · Medium · 21 min read · Analytics & OLAP, Storage engines, Query engines, Performance engineering, Cost optimization
  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.
- [Using Materialized Views in ClickHouse](https://swe.quest/articles/using-materialized-views-in-clickhouse-f547ca7b5675b5e9.md): ClickHouse · 2023-01-19 · Medium · 13 min read · Analytics & OLAP, SQL, Performance engineering, Data pipelines
  ClickHouse materialized views act as insert-time triggers that write the result of a SELECT into a target table, letting expensive aggregations be precomputed.
- [ClickHouse Release 25.11](https://swe.quest/articles/clickhouse-release-25-11-bcf7d5c39dac13b0.md): ClickHouse · 2025-12-05 · Medium · 14 min read · Analytics & OLAP, Query engines, Performance engineering, Concurrency
  ClickHouse 25.11 ships 24 features, 27 performance optimizations and 97 bug fixes.
- [How Rokt Achieved Real-time Reporting with ClickHouse](https://swe.quest/articles/how-rokt-achieved-real-time-reporting-with-clickhouse-89f752e157ebd50c.md): ClickHouse · 2022-12-06 · Easy · 4 min read · Analytics & OLAP, Databases, Cost optimization, E-commerce
  Rokt replaced an Elasticsearch-backed reporting layer with ClickHouse.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
