Skip to main content
Version: Current

Filter

Mode: Streaming Mode: Request-Response

Description

Filter is used to control the flow of data records in the scenarios. It evaluates each incoming data record against a filtering condition and allows only those records that satisfy the condition to pass through. Records that don't meet the condition are either discarded or directed to a "false" branch.

Parameters and configuration

NameDescription
ConditionSpEL expression of type boolean
OutputsAssociates the "true" and "false" condition results with the appropriate branch. You can rearrange this association here, if needed

Filter expression examples

Some common filtering expressions:

// Check if a field exists
#input.containsKey("fieldName")

// Numeric comparison
#input.age > 18

// String comparison
#input.status == "COMPLETED"

// Logical operators
#input.age > 18 && #input.status == "ACTIVE"

// Using functions
#input.timestamp > DATE.parse("2023-01-01")

Additional considerations

Best practices

  1. For complex filtering logic, consider using multiple filters for easier debugging
  2. Use counts functionality to understand how many data records are filtered out by the filter.
  3. Use descriptive names for your filters to document their purpose
  4. Test with sample data to verify filter behavior

For more advanced filtering needs, consider using the Choice component, which allows for multiple conditions and paths.

Why it’s called Filter, not IF?

The Filter node doesn’t make a decision in the classical “flow-chart” sense; it doesn’t control program execution, but rather affects how the data records flow.
Each record arriving at this node is evaluated against the filter condition.
Records for which the condition is true continue through the main path, while records for which it’s false can optionally follow the “False” branch or simply stop flowing further.
Thinking this way — as data records moving through a network of transformations rather than instructions being executed — helps understand how scenarios in Nussknacker work: it’s a data-flow graph, not a decision tree.

See also