I want to trigger the rule if there are two events of same type happened in the same place over the window of 10 seconds.
I have the following rule:
rule "trigger if there were more then 2 events of same type in same place"
when
$event1: Event($props : props, $props.get("EVENT_TYPE") == "FOO_TYPE", $props.containsKey("EVENT_PLACE"))
$eventPlace1: String() from $props.get("EVENT_PLACE")
$events: List(size > 2) from collect(Event($props2 : props,
$props2.get("EVENT_TYPE") == "FOO_TYPE",
$props2.containsKey("EVENT_PLACE"),
$props2.get("EVENT_DATE") == $eventPlace1
) over window:time(10s))
then
System.out.println("rule triggered, the events are: " + $events);
end
The field props
in Event is Map<String, Object>
.
The issue is that this rule gets triggered multiple times instead of once.
For example I'm inserting 4 events, where 3 of them are eligible for this rule e.g. they have same EVENT_TYPE and EVENT_PLACE.
I'm expecting that rule will be fired once, but in reality in fires 3 times, once for each eligible event.
How to achieve the desired behavior ?