# ALIAS and Complicated Search Query

**URL:** https://discuss.elastic.co/t/alias-and-complicated-search-query/220617
**Category:** Elasticsearch
**Created:** [February 24, 2020, 10:04am UTC](https://discuss.elastic.co/t/alias-and-complicated-search-query/220617 "2020-02-24T10:04:56Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Rishabh\_Baid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rishabh_baid/32/48128_2.png) [@Rishabh\_Baid](https://discuss.elastic.co/u/Rishabh_Baid)
#### Post date: [February 24, 2020, 10:04am UTC](https://discuss.elastic.co/t/alias-and-complicated-search-query/220617/1 "2020-02-24T10:04:57Z")

</div>

Hi

I am trying to write this query -

search Elasticsearch docs - in the field - foobar - for anything which has the characters "rix" in it -

Then lets assume we get 500 documents with "rix" in foobar field..

Now I want to check each of the 500 returned docs and see if 5 mins before this doc - was there a doc with characters "abh" in the foobar field. If yes I only want to finally retain and view those "rix" documents.

Example -

I got 500 documents where there is "rix"in foobar field.  
Only for around 100 of these documents - there was an "abh" containing document 5 mins before.

I finally want to view only those 100 "rix" containing docs.

I have the following mySQL query -

SELECT t1.\* FROM sumit\_test AS t1 WHERE t1.foobar LIKE "%rix%" AND TIMESTAMPDIFF(MINUTE,(SELECT t2.@TIMESTAMP FROM sumit\_test AS t2 WHERE t2.foobar LIKE "%abh%"),t1.@TIMESTAMP) \< 5

How do I do it in Elasticsearch DSL???

---

<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 23, 2020, 10:05am UTC](https://discuss.elastic.co/t/alias-and-complicated-search-query/220617/2 "2020-03-23T10:05:04Z")

</div>

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