Filter basics
Filters use MongoDB aggregation pipelines to query alert documents. When an alert matches a filter, it’s published to a Kafka output topic.Filter structure
A filter consists of:- Metadata: Name, description, survey, permissions
- Pipeline: JSON array of MongoDB aggregation stages
- Versions: Multiple pipeline versions with changelog
Writing filter pipelines
Filter pipelines are JSON arrays of aggregation stages. Common stages include:$match: Select alerts
The$match stage filters documents based on field values:
- PSF magnitude is brighter than 18
- RealBogus score is greater than 0.55
$addFields: Compute derived values
$project: Shape output
Alert schema
Filters operate on alert documents stored in MongoDB. Understanding the schema is essential for writing effective filters.ZTF alert schema
Accessing auxiliary data
Filters can access previous photometry and forced photometry using special field names:BOOM automatically loads auxiliary data when filters reference
ZTF.prv_candidates or ZTF.fp_hists.Example filters
Bright supernovae
Select nuclear transients brighter than magnitude 19 with crossmatch to nearby galaxies:Rising fast transients
Select alerts that have brightened by more than 1 magnitude in the last observation:High classification score
Select alerts with high supernova classification scores:Adding filters via CLI
Use theadd_filter binary to add filters to the database:
Run add_filter command
Parameters
- First argument: Survey name (
ztf,lsst, ordecam) - Second argument: Filter name
- Third argument: Path to JSON pipeline file
--description: Optional description (default: “Added via CLI”)
Filter permissions
For surveys with data rights (currently only ZTF), filters must specify which program IDs they can access:Default permissions
Theadd_filter CLI tool sets default permissions:
src/bin/add_filter.rs
Filter validation
BOOM validates filter pipelines before execution:- JSON parsing: Pipeline must be valid JSON array
- MongoDB syntax: Each stage must be valid MongoDB aggregation syntax
- Field references: Referenced fields should exist in alert schema
- Permissions: Survey-specific permission checks
Auxiliary data loading
BOOM optimizes filter execution by only loading auxiliary data when needed:src/filter/ztf.rs
ZTF.prv_candidates: Previous detections are loaded via$lookupZTF.fp_hists: Forced photometry history is loaded via$lookup
Performance tips
Use $match early
Use $match early
Place
$match stages as early as possible in your pipeline to reduce the number of documents processed by subsequent stages.Limit auxiliary data
Limit auxiliary data
Only request auxiliary data you need. Each auxiliary data lookup adds a
$lookup stage.Use indexes
Use indexes
BOOM creates indexes on common fields. Structure your
$match stages to use these indexes:_id(candid)objectIdcandidate.jdcandidate.ra,candidate.dec(2dsphere index)
Avoid heavy computation
Avoid heavy computation
Complex computations in
$addFields can slow down filters. Prefer simple comparisons when possible.Filter versioning
Filters support multiple versions (fv array). This allows you to:
- Update filter logic while preserving history
- A/B test different filter versions
- Roll back to previous versions if needed
fid: Version identifierpipeline: The aggregation pipeline JSONcreated_at: Creation timestamp (Julian Date)changelog: Description of changes
active_fid field specifies which version is currently active.
Next steps
MongoDB aggregation
Learn MongoDB aggregation pipeline syntax
Monitoring
Track filter performance with Prometheus metrics
API reference
Manage filters programmatically via the API