# Search according to document sequence

**URL:** https://discuss.elastic.co/t/search-according-to-document-sequence/25043
**Category:** Elasticsearch
**Created:** [July 7, 2015, 2:05pm UTC](https://discuss.elastic.co/t/search-according-to-document-sequence/25043 "2015-07-07T14:05:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Andrej\_Kurocenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrej_kurocenko/32/3478_2.png) [@Andrej\_Kurocenko](https://discuss.elastic.co/u/Andrej_Kurocenko)
#### Post date: [July 7, 2015, 2:05pm UTC](https://discuss.elastic.co/t/search-according-to-document-sequence/25043/1 "2015-07-07T14:05:40Z")

</div>

Hello,

in elasticsearch I store user events. Such as email sent, email opened, user signed in. Each event is represented by one entry (document) in ES (`{...,"action":"EMAIL_SENT",...}`). Is it possible to query e.g. all users that opened email and then logged in? In other worlds there is sequence of following events in index (ordered by time):

```
{"userId":1, "action":"EMAIL_SENT",...}
{"userId":2, "action":"SOME_ACTION",...}
{"userId":1, "action":"LOG_IN",...}

```

and query should find user with `userId: 1`. Can it be done using only one index? I don't want to merge results of two queries programatically as it may be spatially inefficient.

Thanks for suggestions

---

<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: [July 6, 2017, 12:03am UTC](https://discuss.elastic.co/t/search-according-to-document-sequence/25043/2 "2017-07-06T00:03:11Z")

</div>


