---
title: "Contentsquare Migration from Elasticsearch to ClickHouse"
description: "Contentsquare replaced 14 Elasticsearch clusters with ClickHouse over a phased migration."
url: "https://swe.quest/articles/contentsquare-migration-from-elasticsearch-to-clickhouse-052c118198db3e2f"
canonical: "https://clickhouse.com/blog/contentsquare-migration-from-elasticsearch-to-clickhouse"
source: "ClickHouse"
published: "2022-10-11"
difficulty: "medium"
kind: "Case study"
reading_minutes: 6
tags: ["analytics","refactoring","distributed-databases","performance","cost-optimization"]
---

# Contentsquare Migration from Elasticsearch to ClickHouse

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2022-10-11, 6 min read, Case study. Original: [https://clickhouse.com/blog/contentsquare-migration-from-elasticsearch-to-clickhouse](https://clickhouse.com/blog/contentsquare-migration-from-elasticsearch-to-clickhouse)

## Summary

Contentsquare replaced 14 Elasticsearch clusters with ClickHouse over a phased migration. They first built a new product on ClickHouse, then shadowed production queries endpoint by endpoint to compare results, then moved customers one at a time over six months with zero regressions. The result was 11x lower infrastructure cost, 10x better p99 latency, and longer query windows and retention. Key design pieces were a Kafka-fed ingestion service (clickin) that writes shard-aligned data in ClickHouse native format via clickhouse-local, and an AST-based query optimizer that propagates partition/sort-key conditions and distributed\_group\_by\_no\_merge, merges subqueries, and gave a 10x speedup on the slowest 5% of queries.

Written by swe.quest, not by the author.

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

## Topics

- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [Refactoring & migrations](https://swe.quest/tags/refactoring.md) (Engineering practices)
- [Distributed databases](https://swe.quest/tags/distributed-databases.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Cost optimization](https://swe.quest/tags/cost-optimization.md) (Reliability & operations)

## Prerequisites

- OLAP databases ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))
- database sharding ([easy posts on Databases](https://swe.quest/tags/databases.md?difficulty=easy))
- Kafka basics ([easy posts on Queues & messaging](https://swe.quest/tags/messaging.md?difficulty=easy))

## Keywords

ClickHouse, Elasticsearch, Kafka, clickhouse-local, MergeTree, Contentsquare

## Related posts

- [How trip.com migrated from Elasticsearch and built a 50PB logging solution with ClickHouse](https://swe.quest/articles/how-trip-com-migrated-from-elasticsearch-and-built-a-50pb-logging-solution-with-079ade1f405efcf8.md): ClickHouse · 2024-06-12 · Medium · 16 min read · Analytics & OLAP, Observability, Scaling, Cost optimization, Databases
  Trip.com replaced its Elasticsearch-based centralized logging platform with ClickHouse after hitting stability, ingestion and cost limits at 4PB, and has since grown it toward 50PB.
- [Didi Migrates from Elasticsearch to ClickHouse for a new Generation Log Storage System](https://swe.quest/articles/didi-migrates-from-elasticsearch-to-clickhouse-for-a-new-generation-log-storage-50fcb56512cab39a.md): ClickHouse · 2024-04-19 · Medium · 11 min read · Analytics & OLAP, Observability, Storage engines, Scaling, Cost optimization
  Didi replaced Elasticsearch with ClickHouse for petabyte-per-day log and trace storage, cutting machine cost by 30% and speeding up queries about 4x on a 400+ node single-replica deployment peaking at 40 GB/s writes and ~200 QPS.
- [Why Front migrated from Elasticsearch to ClickHouse for “pixel-perfect” analytics at scale](https://swe.quest/articles/why-front-migrated-from-elasticsearch-to-clickhouse-for-pixel-perfect-analytics-882b7386f623bf53.md): ClickHouse · 2026-11-18 · Easy · 7 min read · Analytics & OLAP, Databases, Developer productivity
  Front moved customer-facing analytics for 9,000+ B2B companies off a 200-node, 25 TB Elasticsearch cluster and onto ClickHouse Cloud.
- [100x Faster: GraphQL Hive migration from Elasticsearch to ClickHouse](https://swe.quest/articles/100x-faster-graphql-hive-migration-from-elasticsearch-to-clickhouse-57650bfdbf95d1a8.md): ClickHouse · 2022-11-03 · Easy · 4 min read · Analytics & OLAP, Observability, GraphQL, Databases, Performance engineering
  GraphQL Hive replaced Elasticsearch with ClickHouse for storing per-request GraphQL monitoring data (consumer, requested fields, latency, request body) after query latency degraded with data growth and one large tenant slowed queries for smaller ones.
- [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)
