Queries
Query System: RunReveal uses ClickHouse as its query engine, giving you access to powerful SQL capabilities for analyzing your log data. All queries support parameterized syntax for flexible, reusable query patterns.

Quick Start
Every RunReveal query follows this basic structure with built-in time parameters:
Key Points:
- Use
`{from:DateTime}`and`{to:DateTime}`for time filtering (automatically set by the UI) - Always use
receivedAtfor time-based queries (it's indexed and handles delayed logs) - Include
LIMITto control result size - Use source-specific views like
aws_cloudtrail_logsinstead oflogswhen possible
Built-in Parameters
RunReveal automatically provides time-based parameters that are populated based on your time range selection in the UI.
{from:DateTime} - Start time (inclusive){to:DateTime} - End time (exclusive){interval:UInt32} - Time bucket in seconds{window:UInt32} - Window duration (default: 14400){paramName:Type} syntaxExample Query with Parameters
Timestamp Fields: receivedAt vs eventTime
Always use receivedAt for time filtering. It's indexed, handles delayed logs, and ensures consistent query performance across all sources.
✓ receivedAt (Recommended)
⚠ eventTime
Best Practice Example
Query Optimization
Follow these best practices to write fast, efficient queries:
Query optimized views like aws_cloudtrail_logs instead of the generic logs table.
Apply filters on indexed fields (receivedAt, sourceType, sourceID) first to reduce dataset size before processing.
Start with 1 hour to test, then expand. Shorter windows process much faster than 30-day ranges.
Prevent processing excessive data by including LIMIT in every query.
Prefer COUNT, GROUP BY over returning all individual events.
When querying the logs table, always include sourceType filter.
Optimizing WHERE Clause Order
Order your WHERE clause filters to match the table's organization. Start with the most specific filters (source type), then narrow by time, and finally add other conditions.
Primary Key Fields (use in this order):
sourceType- Filter by source type first (e.g.,'okta','box','github')sourceID- Include if filtering by a specific source instancereceivedAt- Always include your time range filter
Additional Indexed Fields (use after primary key):
eventTime- When the event occurredsrcIPordstIP- IP addresses (efficient for filtering)actormap values - User informationrawLog- For searching inside raw log data
Example - Optimized Query:
Why This Order Works:
ClickHouse uses the primary key to efficiently prune data. Filtering by sourceType first narrows the dataset to a single source, then receivedAt uses the time-ordered index to skip irrelevant time ranges. Other filters can leverage their indexes after the primary key filters have reduced the dataset size.
Common Pattern:
Most queries should follow this pattern:
Always include sourceType and receivedAt first, then add your specific filters. This pattern ensures optimal query performance.
Common Query Patterns
View Common Query Patterns
ClickHouse Functions Reference
View ClickHouse Functions
Complete Reference: RunReveal uses ClickHouse as its query engine. For a complete list of all available functions, see the ClickHouse Functions Documentation.
toYear(), toMonth(), toHour()toStartOfHour(), toStartOfDay()dateDiff(), formatDateTime()match(), LIKE, extract()splitByChar(), upper(), lower()trim(), replace()arrayJoin(), length(), has()hasAny()map['key'] - Access map valuesmapKeys(), mapValues()has(map, 'key')COUNT(), sum(), avg()quantile(), groupArray()min(), max()if(), multiIf(), coalesce()JSONExtractString(), JSONHas()Common Mistakes to Avoid
❌ Common Mistakes
eventTime for time filteringLIMIT clauselogs without sourceType filterSELECT * with GROUP BY✅ Best Practices
receivedAt for time filteringLIMITsourceType when using logs tableQuick Performance Tips
- Start Small: Test with 1-hour windows before expanding
- Use EXPLAIN: Check execution plans when optimizing
- Monitor Query Time: Watch execution times in the UI
- Index Usage: Filter on indexed columns (receivedAt, sourceType, sourceID)
- Avoid Full Scans: Always include time range filters
- Limit Aggregations: Use LIMIT even with GROUP BY
Related Documentation
- Explore Logs - Learn how to use the query interface
- Writing Detections - Create detection rules from queries
- ClickHouse Documentation - Complete ClickHouse reference
- ClickHouse Functions - All available functions