# Count in Event Correlation

**URL:** <https://discuss.elastic.co/t/count-in-event-correlation/316197>\
**Category:** Elastic Security\
**Tags:** eql-elastic-query-language\
**Created:** [October 10, 2022, 8:52am UTC](https://discuss.elastic.co/t/count-in-event-correlation/316197 "2022-10-10T08:52:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbianco1978](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sbianco1978/32/105266_2.png) [@sbianco1978](https://discuss.elastic.co/u/sbianco1978)\
**Post date:** [October 10, 2022, 8:52am UTC](https://discuss.elastic.co/t/count-in-event-correlation/316197/1 "2022-10-10T08:52:33Z")

</div>

Dears,

I need to create an Event Correlation rule that performs a sequence that group by for a value and meantime count for another value.

My scope is:

sequence by user.name with maxspan=10m and count county \>= 2  
sequence 1  
sequence 2

I couldn't find any way to do it. Could anyone help me?

Thank you.

Best regards

---

<div class="post-metadata">

**Author:** ![justin\_ibarra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_ibarra/32/110828_2.png) [@justin\_ibarra](https://discuss.elastic.co/u/justin_ibarra)\
**Post date:** [October 18, 2022, 6:59pm UTC](https://discuss.elastic.co/t/count-in-event-correlation/316197/2 "2022-10-18T18:59:56Z")

</div>

Hi there 👋,

If I understand your use case correctly, you are not able to due this in a single rule, but you should be able to achieve it leveraging building block [rules](https://www.elastic.co/guide/en/security/current/building-block-rule.html) (BBR) and a threshold [rule](https://www.elastic.co/guide/en/security/current/rules-ui-create.html#create-threshold-rule).

You would need to do this in a few parts:

- ruleA: create a threshold rule where `county > 2` with a lookback (`to` - `from`) of 10m (as a BBR)
- ruleB: create a sequence with `maxspan=10` and `sequence1, sequence2` (as a BBR)
- create a sequence rule alerting on the 2 previous rule alerts:

```auto
sequence by user.name with maxspan=10m
  [any where event.kind == "signal" and kibana.alert.rule.rule_id == "<ruleA.rule_id>"]
  [any where event.kind == "signal" and kibana.alert.rule.rule_id == "<ruleB.rule_id>"]

```

You may have to play with timing of the 2 `maxspan`s and the `lookback` to get it right, but this should achieve what you are trying to do. You also don't necessarily need to use BBR's for the 2 interim rules, but if you don't, then you will get 3 alerts every time this fully completes.

Hope this helps

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 15, 2022, 7:00pm UTC](https://discuss.elastic.co/t/count-in-event-correlation/316197/3 "2022-11-15T19:00:46Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
