Match Recognize
Description
Complex event processing (CEP) finds situations that only a sequence of events reveals: three failed logins followed by
a successful one, a price that keeps falling and then jumps, an aircraft that descends towards a runway and climbs
again instead of landing. The Match Recognize node (match-recognize) detects such sequences: you describe the pattern
in a form - the events it consists of, their conditions and what to return - and the node matches it per key, in event
time, emitting one record per match.
Under the hood the node generates and runs a Flink SQL
MATCH_RECOGNIZE
query over the incoming records, and has its semantics. The SQL is not shown or edited; for a pattern the form cannot
express, write the query in the Flink SQL node.
- The input of the node is one record variable available before the node, usually
#input. Its fields become the columns the conditions and measures refer to, under their own names, plusrecord_time- the record's timestamp, which the pattern is ordered by. - The node clears all upstream variables - after the node only the output variable is available, holding one field per measure.
The node is available only in the Streaming processing mode, for unbounded streams.

When to use it
A Filter looks at one event; an aggregate sums up many of them. Neither can say that one kind of event was followed by another - that a login failed three times and then succeeded, that a card was used in two countries within an hour, that a sensor reading kept falling and then jumped, that an aircraft was about to land and climbed away instead. Match Recognize is for that: a situation that only shows in a sequence of events of one key, in order, within a time. Typical uses are fraud and abuse detection (a sequence of operations that no single one gives away), customer journeys (an abandoned basket, a repeated failure before a churn), telecom and IoT alarms (a degradation that continues, a device that reboots in a loop), and operational monitoring like the flight example below.
When the sequence is only two events and the question is "has this key been seen before", the Deduplication node or a Previous Value is simpler. When the question is a count or a sum over a window, use an aggregate.
How a pattern is matched
- The stream is split into independent groups by Partition by - usually the key of the thing being watched: an account, a device, an aircraft. Each group is matched on its own, so a pattern never mixes events of two keys.
- Within a group, events are taken in the order of Order by, which has to be the time attribute
record_timeascending. Flink needs it for deterministic matching; out-of-order events are sorted by the watermark first. - The pattern is a regular expression over events. Each pattern variable (A, B, C, ...) stands for one kind of event, defined by its conditions; a quantifier says how many consecutive events of that kind may follow each other.
- When a sequence matches, the measures compute the values returned for it, e.g. the time of its first event or the altitude of its last one. One record per match is emitted, with the measures as its fields.
- After match decides where the search continues, and Within limits how long a match may take.