# Query to get documents having specific message and time difference between documents should not be more than 5 mins

**URL:** https://discuss.elastic.co/t/query-to-get-documents-having-specific-message-and-time-difference-between-documents-should-not-be-more-than-5-mins/102840
**Category:** Elasticsearch
**Created:** [October 5, 2017, 12:52pm UTC](https://discuss.elastic.co/t/query-to-get-documents-having-specific-message-and-time-difference-between-documents-should-not-be-more-than-5-mins/102840 "2017-10-05T12:52:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![piyush26th](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@piyush26th](https://discuss.elastic.co/u/piyush26th)
#### Post date: [October 5, 2017, 12:52pm UTC](https://discuss.elastic.co/t/query-to-get-documents-having-specific-message-and-time-difference-between-documents-should-not-be-more-than-5-mins/102840/1 "2017-10-05T12:52:12Z")

</div>

Hi Team,

I want to get documents having specific messages and time difference between documents should not be more than 5 mins.

For eg.  
I have documents with messages "abc" and "xyz" in any index.  
Now I want to get all documents having message "abc" OR "xyz" AND time difference between these documents should not be more than 5 mins.

I have researched on this but did not find elastic search query to get such documents. Could you please help me with this ?

Thanks,  
Piyush Srivastava

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 5, 2017, 1:49pm UTC](https://discuss.elastic.co/t/query-to-get-documents-having-specific-message-and-time-difference-between-documents-should-not-be-more-than-5-mins/102840/2 "2017-10-05T13:49:15Z")

</div>

I don't believe you can do that: comparing the values between 2 different documents.

You probably need to think your model a bit differently if possible.  
It depends on the use case I guess.

---

<div class="post-metadata">

### Author: ![piyush26th](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@piyush26th](https://discuss.elastic.co/u/piyush26th)
#### Post date: [October 5, 2017, 2:40pm UTC](https://discuss.elastic.co/t/query-to-get-documents-having-specific-message-and-time-difference-between-documents-should-not-be-more-than-5-mins/102840/3 "2017-10-05T14:40:23Z")

</div>

ok. Thanks

---

<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: [November 2, 2017, 2:40pm UTC](https://discuss.elastic.co/t/query-to-get-documents-having-specific-message-and-time-difference-between-documents-should-not-be-more-than-5-mins/102840/4 "2017-11-02T14:40:39Z")

</div>

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