# Aggregating sequence of connected events

**URL:** <https://discuss.elastic.co/t/aggregating-sequence-of-connected-events/264421>\
**Category:** Elasticsearch\
**Created:** [February 16, 2021, 11:25am UTC](https://discuss.elastic.co/t/aggregating-sequence-of-connected-events/264421 "2021-02-16T11:25:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![steff1](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@steff1](https://discuss.elastic.co/u/steff1)\
**Post date:** [February 16, 2021, 11:25am UTC](https://discuss.elastic.co/t/aggregating-sequence-of-connected-events/264421/1 "2021-02-16T11:25:48Z")

</div>

Lets say I have events like this in my log

```auto
{type:"approval_revokation", approval_id=22}
{type:"approval", request_id=12, approval_id=22}
{type:"control3", request_id=12}
{type:"control2", request_id=12}
{type:"control1", request_id=12}
{type:"request", request_id=12 requesting_user="user1"}
{type:"registration", userid="user1"}

```

I would like to do a search that aggregates one bucket for each approval containing all events connected to it as above. As you see there is not a single id field that can be used throughout the events, but they are all connected in a chain.

The reason I would like this is to feed this into a anomaly detector to verify things like that all controls where executed and validate registration event for a eventual approval.

Can this be done using aggregation or are there any other suggestion?

---

<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:** [March 16, 2021, 11:26am UTC](https://discuss.elastic.co/t/aggregating-sequence-of-connected-events/264421/2 "2021-03-16T11:26:47Z")

</div>

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