Fix date histogram cache miss: replace now with cacheable date bounds#108
Conversation
ES cannot cache filter bitsets for queries containing time-relative expressions like `now` or `now-2000y` — the value changes each millisecond, so ES skips the query cache entirely. With ~2,000 requests/minute each triggering a full BKD tree traversal of a 2,000-year date range, this drives ES nodes to 85–99% CPU. Replace relative lower bounds with fixed epoch dates (fully cacheable) and the `now` upper bound with `now/d` (rounds to current day, cached for up to 24 hours). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe pull request changes date facet aggregation lower-bound ( ChangesDate Facet Aggregation Bounds
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
Summary
now-2000yandnow-416ylower bounds with fixed epoch dates (0001-01-01,1600-01-01)nowupper bound withnow/d(rounds to current day)Why
ES cannot cache filter bitsets for any query containing a
now-relative expression — the value changes each millisecond, so ES skips the query cache entirely. The_statsendpoint on the active index shows 299 million cache misses vs 2.3 million hits (0.76% hit rate), meaning virtually every date histogram query forces a full BKD tree traversal of a range spanning 2,000 years (~730,000 day-resolution BKD nodes per shard).With ~2,000 requests/minute of frontend search traffic, each triggering this traversal, ES nodes are running at 85–99% CPU and the Akka circuit breaker fires repeatedly.
Fix
Fixed lower bounds (
0001-01-01,1600-01-01) are fully cacheable — the bitset is computed once per shard and reused.now/dfor the upper bound rounds to midnight UTC, making it constant for the full day. Cache hit rate should improve dramatically, dropping per-query CPU cost for date histogram aggregations from O(BKD-traversal) to O(cache-lookup) for the vast majority of requests.Test plan
_stats.query_cache.hit_count— expect hit rate to climb above 50% within minutes🤖 Generated with Claude Code
Fix date histogram cache miss: replace now with cacheable date bounds
This PR modifies Elasticsearch date histogram aggregation queries to improve query-cache effectiveness and reduce expensive BKD traversal work.
Changes
Motivation and expected effect
Test plan
Compatibility & impact notes (explicit)
Other notes