Skip to main content
Version: Next

Aggregation Operators

The aggregation operators are used within the conditional query to post-process or throttle matched records. They can be combined with other logical and comparison operators.

The following aggregation operators are supported:

OperatorReductStore VersionDescription
$each_nv1.16Keeps each N-th record after previous condition
$each_tv1.16Keeps a record after the previous condition once in time interval
$gatev1.19Opens a fixed time window on false -> true, then forces false until reset
$limitv1.16Limits the number of records to be processed in the query
info

The order of operators affects the result. Conditions are applied sequentially, so placing an aggregation operator before or after a filter changes the outcome.

$each_n

The $each_n operator is used to keep each N-th record after the previous condition.

Syntax

{
"$each_n": [ <expression as integer> ]
}

Behavior

The operator evaluates the first expression as an integer and uses it to select every N-th matching record.

Examples

Filter records with a score greater than 10, then return every 5th record from the result:

{
"&score": { "$gt": 10 },
"$each_n": 5
}

Select every 5th record, then return those with a score greater than 10:

{
"$each_n": 5,
"&score": { "$gt": 10 }
}

$each_t

The $each_t operator keeps a record if its timestamp is at least the specified number of seconds after the previous matching record.

Syntax

{
"$each_t": [ <duration> | <expression as float> ]
}

Behavior

The operator supports a duration in the format of 5s (5 seconds) or a float value representing seconds:

  • If the operand is a duration literal (e.g., 5s), it is used directly.
  • If some other expression is provided, it is evaluated as a float and interpreted as seconds.

Examples

Filter records with a score greater than 10, then return only those that are at least 5 seconds apart.

{
"&score": { "$gt": 10 },
"$each_t": "5s"
}

Keep only records at least 5 seconds apart, then filter for scores greater than 10:

{
"$each_t": "5s",
"&score": { "$gt": 10 }
}

$gate

The $gate operator opens a time-bounded gate when the input condition changes from false to true. While the gate is open, output mirrors the input condition. Once the time window expires, output is forced to false until the input is reset to false and a new false -> true edge occurs.

Syntax

{
"$gate": [ <duration> | <expression as float>, <condition> ]
}

Behavior

  • The first operand is the gate duration ("10s", "250ms", or 0.5 for seconds).
  • The second operand is a condition expression that evaluates to boolean.
  • On false -> true, the gate opens for the duration.
  • While open, output equals the input condition.
  • After timeout, output is always false.
  • The gate will not re-open while input remains true; input must return to false first.

Examples

Open a 10-second window when motion=true, and pass only records during the active window:

{
"$gate": ["10s", { "&motion": { "$eq": true } }]
}

Open a 500ms gate after high anomaly score is first detected:

{
"$gate": [0.5, { "@anomaly_score": { "$gt": 0.8 } }]
}

$limit

The $limit operator restricts the result set to a maximum of N records.

Syntax

{
"$limit": [ <expression as integer> ]
}

Behavior

The operator evaluates the first expression as an integer and uses it to limit the number of records to be processed in the query. The operator is applied after the previous condition, so it limits the number of records that match the previous condition.

Examples

Limit the number of records whose score is greater than 10 to 5:

{
"&score": { "$gt": 10 },
"$limit": 5
}

Find records with a score greater than 10 in the first 5 records:

{
"$limit": 5,
"&score": { "$gt": 10 }
}