# Query the last 5 minutes

**URL:** https://discuss.elastic.co/t/query-the-last-5-minutes/80043
**Category:** Elasticsearch
**Created:** [March 26, 2017, 1:48pm UTC](https://discuss.elastic.co/t/query-the-last-5-minutes/80043 "2017-03-26T13:48:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)
#### Post date: [March 26, 2017, 1:48pm UTC](https://discuss.elastic.co/t/query-the-last-5-minutes/80043/1 "2017-03-26T13:48:43Z")

</div>

Hi,

I am trying to look for a solution to query the last 5 minutes, depending on what time is it.  
That means I dont want to manually enter the time such as:

```
GET filebeat-*/log/_search
{"query" : {
 "range" : { 
            "msgSubmissionTime" : { "from" : "January 18th 2017, 17:17:56.973", "to" : January 18th "2017, 17:22:56.973" } 
        } 
  }
}

```

I will like to do something like this:

```
GET filebeat-*/log/_search
{"query" :
   {
       "range" : { 
            "msgSubmissionTime" : { "from" : "5 minutes ago", "to" : "now" } 
        } 
   }
}

```

Thanks for any help 🙂

---

<div class="post-metadata">

### Author: ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)
#### Post date: [March 26, 2017, 2:13pm UTC](https://discuss.elastic.co/t/query-the-last-5-minutes/80043/2 "2017-03-26T14:13:44Z")

</div>

I found this:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html)

I had to change it a little bit (for some reason with my ES the concept of now/m or now/m)

Here is my curl:

```
curl -XGET '192.168.1.114:9200/filebeat-*/log/_search?pretty' -H 'Content-Type: application/json' -d'
{
    "query": {
        "range" : {
            "msgSubmissionTime" : {
                "gte" : "now-2m",
                "lt" : "now"
            }
        }
    }
}
```

---

<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 23, 2017, 2:14pm UTC](https://discuss.elastic.co/t/query-the-last-5-minutes/80043/3 "2017-04-23T14:14:08Z")

</div>

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