# Aggregate on a sequence item in EQL

**URL:** <https://discuss.elastic.co/t/aggregate-on-a-sequence-item-in-eql/259116>\
**Category:** Elasticsearch\
**Created:** [December 18, 2020, 2:41pm UTC](https://discuss.elastic.co/t/aggregate-on-a-sequence-item-in-eql/259116 "2020-12-18T14:41:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayden.mckay](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@jayden.mckay](https://discuss.elastic.co/u/jayden.mckay)\
**Post date:** [December 18, 2020, 2:41pm UTC](https://discuss.elastic.co/t/aggregate-on-a-sequence-item-in-eql/259116/1 "2020-12-18T14:41:26Z")

</div>

Hi all 🙂

I am trying to run an EQL search where the first item must occur X amount of times or more before the second item in the sequence will be ran. Anyone know how I can do this?

AKA for the example below, I want to see if a new session was started to a device and a successful log in occurs, but I would like to see if a sessions was started 5 or more times before a successful log in.

```auto
    GET /OMITTEDINDEX/_eql/search
        {
          "query": """
          sequence by client.ip with maxspan=30s
              [any where event.record_type == "SSL_HANDSHAKE_SUCCESS" and service.type == "Session New" and client.ip == "OMITTEDIP"] 
              [any where event.record_type == "LOGIN"]
          """
        }

```

---

<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:** [January 15, 2021, 2:41pm UTC](https://discuss.elastic.co/t/aggregate-on-a-sequence-item-in-eql/259116/2 "2021-01-15T14:41:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![matriv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matriv/32/43656_2.png) [@matriv](https://discuss.elastic.co/u/matriv)\
**Post date:** [January 18, 2021, 8:48am UTC](https://discuss.elastic.co/t/aggregate-on-a-sequence-item-in-eql/259116/3 "2021-01-18T08:48:44Z")

</div>

There is no syntactic sugar to do this, you need to define the first matching query 5 times:

```auto
sequence by client.ip with maxspan=30s
              [any where event.record_type == "SSL_HANDSHAKE_SUCCESS" and service.type == "Session New" and client.ip == "OMITTEDIP"] 
              [any where event.record_type == "SSL_HANDSHAKE_SUCCESS" and service.type == "Session New" and client.ip == "OMITTEDIP"] 
              [any where event.record_type == "SSL_HANDSHAKE_SUCCESS" and service.type == "Session New" and client.ip == "OMITTEDIP"] 
              [any where event.record_type == "SSL_HANDSHAKE_SUCCESS" and service.type == "Session New" and client.ip == "OMITTEDIP"] 
              [any where event.record_type == "SSL_HANDSHAKE_SUCCESS" and service.type == "Session New" and client.ip == "OMITTEDIP"] 
              [any where event.record_type == "LOGIN"]

```
