LangWatch v3 replaces Elasticsearch/OpenSearch with ClickHouse as the primary data store. This guide walks you through the full migration. The process is the same whether you're coming from v1.x or v2.x.
This is a zero-downtime migration. Elasticsearch and ClickHouse run side-by-side during the transition. New data flows to ClickHouse immediately, and you migrate historical data at your own pace.
What Changed
- Data store: Trace, span, and evaluation data is now stored in ClickHouse instead of Elasticsearch/OpenSearch
- Architecture: New event-sourcing system for data processing
- Helm charts: New composable overlay structure with
clickhouse-serverlesssubchart - Environment:
ELASTICSEARCH_*variables replaced byCLICKHOUSE_URL
Migration Steps Overview
- Back up your databases
- Deploy ClickHouse alongside your existing Elasticsearch
- Upgrade LangWatch to v3
- Migrate historical data from Elasticsearch to ClickHouse
- Remove Elasticsearch
Prerequisites
- Back up your databases: see Backups
- Check release notes at github.com/langwatch/langwatch/releases
- Test in staging before upgrading production
- Verify your Elasticsearch cluster is healthy (all shards green)
- Ensure you have enough disk space on the ClickHouse host for the migrated data
Step 1: Deploy ClickHouse
Add ClickHouse to your existing infrastructure. Your Elasticsearch instance stays running, both operate in parallel during migration.
Docker Compose
Set a password for ClickHouse's default user in your .env. Keep it URL-safe, because the app carries it inside CLICKHOUSE_URL. Without one the file below falls back to the published langwatch, which ClickHouse warns about at every boot and the next major release removes:
echo "CLICKHOUSE_PASSWORD=$(openssl rand -hex 24)" >> .envAdd the ClickHouse service to your compose.yml:
services: clickhouse: image: langwatch/clickhouse-serverless:0.4.0 environment: CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:-langwatch} ports: - "8123:8123" volumes: - clickhouse-data:/var/lib/clickhouse deploy: resources: limits: memory: 2G healthcheck: test: ["CMD", "clickhouse-client", "--query", "SELECT 1"] interval: 5s timeout: 5s retries: 5volumes: clickhouse-data:Kubernetes (Helm)
The v3 Helm chart includes the clickhouse-serverless subchart automatically. No additional setup is needed; the chart deploys ClickHouse when you upgrade it in Step 2.
Step 2: Upgrade LangWatch to v3
Docker Compose
Update your environment variables and pull the v3 images:
Add CLICKHOUSE_URL to your app and workers environment in compose.yml:
services: app: environment: CLICKHOUSE_URL: http://default:${CLICKHOUSE_PASSWORD:-langwatch}@clickhouse:8123/langwatch workers: environment: CLICKHOUSE_URL: http://default:${CLICKHOUSE_PASSWORD:-langwatch}@clickhouse:8123/langwatchThen pull and restart:
docker compose pulldocker compose up -dHelm Chart
helm repo updatehelm upgrade langwatch langwatch/langwatch \ --namespace langwatch \ -f values-production.yaml \ --wait --timeout 10mThe Helm chart configures CLICKHOUSE_URL automatically from the ClickHouse values, no manual env
var needed for either managed or external ClickHouse.
What Happens on Startup
- PostgreSQL: Prisma migrations run automatically, including removing the old Elasticsearch feature flags
- ClickHouse: Schema migrations create all required tables (
event_log,stored_spans,trace_summaries, etc.) - New data starts flowing to ClickHouse immediately
- Historical data in Elasticsearch remains readable until you migrate it
Keep your ELASTICSEARCH_NODE_URL configured during this phase. LangWatch v3 can still read from
Elasticsearch for data that hasn't been migrated yet.
Step 3: Migrate Historical Data
The es-migration tool reads documents from Elasticsearch and writes them to ClickHouse via the event-sourcing system. It runs outside of your LangWatch deployment, no Redis or BullMQ needed.
Setup
# Clone the repositorygit clone https://github.com/langwatch/langwatch.git# Install dependencies. The repo is a single pnpm workspace, so one# install at the repo root covers everythingpnpm install# Navigate to the migration toolcd packages/es-migrationConfigure
Set the required environment variables:
export ELASTICSEARCH_NODE_URL="http://localhost:9200"# Your shell does not load .env: export CLICKHOUSE_PASSWORD first, or the published default applies.export CLICKHOUSE_URL="http://default:${CLICKHOUSE_PASSWORD:-langwatch}@localhost:8123/langwatch"# If your Elasticsearch requires authenticationexport ELASTICSEARCH_API_KEY="your-api-key"Point these at your actual Elasticsearch and ClickHouse instances. If they're running in Docker or Kubernetes, you may need to set up port forwarding or use the internal network addresses.
Credential requirements:
- Elasticsearch: Use a read-only user or API key. The migration tool only reads from ES, a read-only credential protects your source data from accidental writes.
- ClickHouse: Use a user with write access. The tool needs to insert into
event_logand projection tables.
Disable ClickHouse TTLs Before Migrating
This step is critical. If you skip it, ClickHouse may immediately expire or offload historical data as it arrives during migration.
LangWatch uses TTL rules to manage data retention and tiered storage in ClickHouse. With cold storage on, data older than 49 days moves to S3. Separately, data retention deletes data past its retention period, which defaults to 49 days. When you migrate historical data from Elasticsearch, much of it is older than 49 days, so ClickHouse tries to offload or delete it the moment it lands.
To keep history older than 49 days, set a longer retention policy before you import. That needs a license: without one the deployment keeps the 49-day default, and older history is deleted as it lands.
With cold storage on, also raise its TTL before starting the migration, so migrated data stays in hot storage:
A per-table variable such as CLICKHOUSE_COLD_STORAGE_SPANS_TTL_DAYS takes precedence over the default. If you set any of them on the app or workers, raise or remove them too, then check the effective TTL with SHOW CREATE TABLE before you import history.
Docker Compose
Add to your app and workers environment:
services: app: environment: CLICKHOUSE_COLD_STORAGE_DEFAULT_TTL_DAYS: "9999" workers: environment: CLICKHOUSE_COLD_STORAGE_DEFAULT_TTL_DAYS: "9999"Then restart:
docker compose up -dHelm Chart
The chart sets CLICKHOUSE_COLD_STORAGE_DEFAULT_TTL_DAYS on the app and workers from clickhouse.cold.defaultTtlDays when cold storage is on. Raise that value instead of adding the variable through extraEnvs:
clickhouse: cold: defaultTtlDays: 9999Then upgrade:
helm upgrade langwatch langwatch/langwatch \ --namespace langwatch \ -f values-production.yaml \ --wait --timeout 10mThe TTL reconciler runs on startup and updates the ClickHouse table metadata without reorganizing existing data. ClickHouse then moves any data the new TTL policy assigns to a different storage tier, asynchronously.
After Migration: Restore TTLs
Once the migration is complete, set CLICKHOUSE_COLD_STORAGE_DEFAULT_TTL_DAYS (Helm: clickhouse.cold.defaultTtlDays) back to your desired value and restart LangWatch. ClickHouse handles the offloading gracefully in the background.
We recommend setting TTL values to a multiple of 7 (e.g., 7, 14, 28, 49) to align with ClickHouse partition boundaries for more efficient data management.
Migration Targets
The tool migrates data in separate targets:
| Target | Description |
|---|---|
traces-combined | Traces and their evaluations |
simulations | Simulation run events |
batch-evaluations | Batch experiment evaluation data |
dspy-steps | DSPy optimization steps |
all | Run all primary targets in sequence |
Testing Workflow
Start small and verify before running the full migration:
1. Dry-run a single batch: validate the mapping without writing anything:
pnpm tsx src/index.ts traces-combined --dry-run --single-batchReview the output in ./dry-run-traces-combined.json to confirm the data looks correct.
2. Live single batch: process one batch and verify in ClickHouse:
pnpm tsx src/index.ts traces-combined --single-batch3. Limited run: process a few thousand events to catch edge cases:
MAX_EVENTS=5000 pnpm tsx src/index.ts traces-combined4. Full migration: migrate everything:
pnpm tsx src/index.ts allFor large history systems, we recommend running one target at a time instead of all, so you can
apply the tuning profiles below for each target individually.
Recommended Tuning
Each target has different document sizes and volumes, so tuning per-target improves throughput.
Traces and evaluations (large volume):
export BATCH_SIZE=5000export SUB_BATCH_SIZE=2000export CH_BATCH_SIZE=5000export CONCURRENCY=1000export CURSOR_REWIND_MS=21600000DSPy steps (smaller documents):
export BATCH_SIZE=100export CH_BATCH_SIZE=100export CONCURRENCY=10export CURSOR_REWIND_MS=21600000Runtime Controls
- Pause/Resume: Press
pduring migration to pause after the current batch. Presspagain to resume. - Graceful shutdown:
Ctrl+Cfinishes the current batch then exits. Press again to force quit. - ClickHouse backpressure: The tool monitors ClickHouse merge load and pauses automatically when it's too high. It resumes when merges catch up.
Resume After Interruption
The migration saves progress to a cursor file (e.g., ./cursor-traces-combined.json). If interrupted, it resumes from the last checkpoint on restart.
To start a target from scratch, delete its cursor file.
Verify the Migration
After migration completes, verify the data in ClickHouse:
# Connect to ClickHouseclickhouse-client --host localhost --port 9000# Check trace countsSELECT COUNT(*) FROM langwatch.trace_summaries;# Check event logSELECT AggregateType, COUNT(*) FROM langwatch.event_log GROUP BY AggregateType;Compare these counts against your Elasticsearch indices to confirm completeness. Note that you may wish to run a distinct check against the ProjectionId column on trace summaries as if there are any MergeTree Replacements that need to happen it could cause the count operation to report duplicates in the count.
Step 4: Remove Elasticsearch
Once you've verified the migration:
-
Remove Elasticsearch environment variables from your configuration:
ELASTICSEARCH_NODE_URLELASTICSEARCH_API_KEY
-
Remove the Elasticsearch service from your
compose.ymlor Helm values -
Restart LangWatch to apply the changes
Docker Compose
# After removing the elasticsearch service from compose.ymldocker compose up -dHelm
helm upgrade langwatch langwatch/langwatch \ --namespace langwatch \ -f values-production.yaml \ --wait --timeout 10mEnvironment Variable Changes
| Variable | v1.x, v2.x | v3.0 |
|---|---|---|
ELASTICSEARCH_NODE_URL | Required | Remove |
ELASTICSEARCH_API_KEY | Optional | Remove |
CLICKHOUSE_URL | , | Required |
All other environment variables remain the same. See Environment Variables for the full reference.
Troubleshooting
Toxic documents
If a single Elasticsearch document is too large and crashes an ES shard during migration, the tool detects this, skips the problematic document, and logs its ID to ./skipped-toxic-docs.log. These documents may need manual handling.
Response too large
If an Elasticsearch response exceeds the Node.js string limit (~1 GB), the tool automatically halves the batch size and retries.
Transient Elasticsearch errors
For timeouts or connection issues, the tool uses exponential backoff (up to 5 retries) and reduces batch size if errors persist.
Migration seems slow
- Check ClickHouse merge load in the progress output (
ch_partscolumn) - Increase
CONCURRENCYandBATCH_SIZEif your hardware can handle it - The tool auto-pauses when ClickHouse is under merge pressure, this is normal
Getting Help
- Check the Troubleshooting guide
- Open an issue at github.com/langwatch/langwatch/issues
- Contact support