# How to query elasticsearch to get data between two timestamps

**URL:** <https://discuss.elastic.co/t/how-to-query-elasticsearch-to-get-data-between-two-timestamps/79311>\
**Category:** Elasticsearch\
**Created:** [March 20, 2017, 7:47pm UTC](https://discuss.elastic.co/t/how-to-query-elasticsearch-to-get-data-between-two-timestamps/79311 "2017-03-20T19:47:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Hoffman](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@Ben\_Hoffman](https://discuss.elastic.co/u/Ben_Hoffman)\
**Post date:** [March 20, 2017, 7:47pm UTC](https://discuss.elastic.co/t/how-to-query-elasticsearch-to-get-data-between-two-timestamps/79311/1 "2017-03-20T19:47:54Z")

</div>

Recently I have been using a timestamp based query to get data form my ELK stack and avoid repeats. Now I would like to implement getting information between two specific timestamps.

Here is my current query:

```
{
  "query": {
    "range": {
      "runtime_timestamp": {
       "gt": "2017-03-18T22:00:55.964Z"
    }  
   }
  },
  "_source": {
  "includes": [
  "field1",
  "field2"
]
},
"sort": [
{
  "@timestamp": {
    "order": "desc"
  }
}
]
}

```

I have looked at the docs and I can't seem to find a way to do it. Any ideas?

---

<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:** [March 20, 2017, 8:03pm UTC](https://discuss.elastic.co/t/how-to-query-elasticsearch-to-get-data-between-two-timestamps/79311/2 "2017-03-20T20:03:29Z")

</div>

Add also lt or lte in the range query.

---

<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:** [April 17, 2017, 8:03pm UTC](https://discuss.elastic.co/t/how-to-query-elasticsearch-to-get-data-between-two-timestamps/79311/3 "2017-04-17T20:03:49Z")

</div>

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