# Is it possible to build a query with a relative clause (like self join) - maybe ES2?

**URL:** https://discuss.elastic.co/t/is-it-possible-to-build-a-query-with-a-relative-clause-like-self-join-maybe-es2/26790
**Category:** Elasticsearch
**Created:** [August 4, 2015, 10:23am UTC](https://discuss.elastic.co/t/is-it-possible-to-build-a-query-with-a-relative-clause-like-self-join-maybe-es2/26790 "2015-08-04T10:23:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![yehosef](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yehosef/32/42175_2.png) [@yehosef](https://discuss.elastic.co/u/yehosef)
#### Post date: [August 4, 2015, 10:23am UTC](https://discuss.elastic.co/t/is-it-possible-to-build-a-query-with-a-relative-clause-like-self-join-maybe-es2/26790/1 "2015-08-04T10:23:31Z")

</div>

We are trying to build a funnel for user actions to find users that are doing one action and then another. The assumed approach for now is to have a "member" document which has child documents of "actions" which have the action name and other properties that we want.

The idea is that I need to see people that did action1 and then did action2, where the order and perhaps time interval is important. So it's easy to get where I have people that did action1 and action2, the hard part is making this relative. Ideally I would want to say something like "where action2.name = 'signup' and action2.timestamp \> action1.timestamp";

So these seems like a join, which isn't going to be possible. But I thought maybe there is some trick I don't know about or some other way to store the data or ask the question to accomplish the same thing.

I also thought that perhaps with the pipeline aggregations in ES2 I would be able to do this - but I'm not sure how.

Any ideas or 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 5, 2017, 11:57pm UTC](https://discuss.elastic.co/t/is-it-possible-to-build-a-query-with-a-relative-clause-like-self-join-maybe-es2/26790/2 "2017-07-05T23:57:34Z")

</div>


