# Performing between operation on documents in Elasticsearch

**URL:** https://discuss.elastic.co/t/performing-between-operation-on-documents-in-elasticsearch/50550
**Category:** Elasticsearch
**Created:** [May 20, 2016, 11:23am UTC](https://discuss.elastic.co/t/performing-between-operation-on-documents-in-elasticsearch/50550 "2016-05-20T11:23:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ApoorvaLad](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@ApoorvaLad](https://discuss.elastic.co/u/ApoorvaLad)
#### Post date: [May 20, 2016, 11:23am UTC](https://discuss.elastic.co/t/performing-between-operation-on-documents-in-elasticsearch/50550/1 "2016-05-20T11:23:30Z")

</div>

Can we perform a between query within multiple documents?  
For eg:

consider document1. There is message field in this document which says "Call initialised".  
Consider document 2. There is a message field which says "Call started".  
Consider document 3. There is a message field which says "Call ended".

Now I want to search between "Call Initialised " and "Call end" messages which should fetch me all messages between these two messages.

Range query on timestamp is not possible, as I have 1000 records for the same timestamp.

Can anyone help me with the same?

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [May 20, 2016, 7:09pm UTC](https://discuss.elastic.co/t/performing-between-operation-on-documents-in-elasticsearch/50550/2 "2016-05-20T19:09:16Z")

</div>

It seems like the order of documents is important for your use case. So, maybe, you can add a "sequence number" field that would increment for each document that you index. This way you will be able to have better resolution than timestamp provides and be able to use range queries.

---

<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, 10:50pm UTC](https://discuss.elastic.co/t/performing-between-operation-on-documents-in-elasticsearch/50550/3 "2017-07-05T22:50:04Z")

</div>


