# How to query for the most current timestamp

**URL:** https://discuss.elastic.co/t/how-to-query-for-the-most-current-timestamp/134746
**Category:** Elasticsearch
**Created:** [June 6, 2018, 7:20am UTC](https://discuss.elastic.co/t/how-to-query-for-the-most-current-timestamp/134746 "2018-06-06T07:20:31Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![yks](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@yks](https://discuss.elastic.co/u/yks)
#### Post date: [June 6, 2018, 7:20am UTC](https://discuss.elastic.co/t/how-to-query-for-the-most-current-timestamp/134746/1 "2018-06-06T07:20:31Z")

</div>

Hi,

Would like to know how to query for the most current timestamp and display on dashboard.

Best regards

---

<div class="post-metadata">

### Author: ![Magnus\_Kessler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnus_kessler/32/42001_2.png) [@Magnus\_Kessler](https://discuss.elastic.co/u/Magnus_Kessler)
#### Post date: [June 6, 2018, 6:58pm UTC](https://discuss.elastic.co/t/how-to-query-for-the-most-current-timestamp/134746/2 "2018-06-06T18:58:33Z")

</div>

The actual query would be something like

```auto
GET _search
{
  "size": 0,
  "aggs": {
    "most_recent": {
      "max": {
        "field": "@timestamp"
      }
    }
  }
}

```

This translates directly into the aggregation you'd configure for a `metric` visualisation.

---

<div class="post-metadata">

### Author: ![yks](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@yks](https://discuss.elastic.co/u/yks)
#### Post date: [June 7, 2018, 8:20am UTC](https://discuss.elastic.co/t/how-to-query-for-the-most-current-timestamp/134746/3 "2018-06-07T08:20:25Z")

</div>

Hi Magnus,

Thanks.

I tried to use the query at Kibana Dev Tool and received this error

> ```
> {
> "took": 23,
> "timed_out": false,
> "_shards": {
> "total": 26,
> "successful": 26,
> "skipped": 0,
> "failed": 0
> },
> "hits": {
> "total": 13,
> "max_score": 0,
> "hits": []
> },
> "aggregations": {
> "most_recent": {
> "value": null
> }
> }
> }
> 
> ```

```
When i search using the full search

```

> ```
> GET _search
> {
> "query": {
> "match_all": {}
> }
> }
> 
> ```

I have this index customer with timestamp which I need to retrieve the latest timestamp

> {  
> "\_index": "customer",  
> "\_type": "type1",  
> "\_id": "iyBNkGMBMi0XPkSP1tgf",  
> "\_score": 1,  
> "\_source": {  
> "Connect": "Y",  
> "Timestamp": "2018-05-24 09:00:00"  
> }  
> }  
> ]  
> }

---

<div class="post-metadata">

### Author: ![Magnus\_Kessler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnus_kessler/32/42001_2.png) [@Magnus\_Kessler](https://discuss.elastic.co/u/Magnus_Kessler)
#### Post date: [June 7, 2018, 8:34am UTC](https://discuss.elastic.co/t/how-to-query-for-the-most-current-timestamp/134746/4 "2018-06-07T08:34:37Z")

</div>

The timestamp field in your data model is called `Timestamp`. Try replacing `@timestamp` in the example query with the actual field name.

---

<div class="post-metadata">

### Author: ![yks](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@yks](https://discuss.elastic.co/u/yks)
#### Post date: [June 7, 2018, 8:50am UTC](https://discuss.elastic.co/t/how-to-query-for-the-most-current-timestamp/134746/5 "2018-06-07T08:50:49Z")

</div>

Ok, I changed to Timestamp but the result did not display the latest timestamp

> ```
> GET _search
> {
> "size": 0,
> "aggs": {
> "most_recent": {
> "max": {
> "field": "Timestamp"
> }
> }
> }
> }
> 
> ```

Result

> ```
> {
> "took": 5,
> "timed_out": false,
> "_shards": {
> "total": 21,
> "successful": 21,
> "skipped": 0,
> "failed": 0
> },
> "hits": {
> "total": 12,
> "max_score": 0,
> "hits": []
> },
> "aggregations": {
> "most_recent": {
> "value": 1527152400000
> }
> }
> }
> 
> ```

---

<div class="post-metadata">

### Author: ![Magnus\_Kessler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnus_kessler/32/42001_2.png) [@Magnus\_Kessler](https://discuss.elastic.co/u/Magnus_Kessler)
#### Post date: [June 7, 2018, 12:18pm UTC](https://discuss.elastic.co/t/how-to-query-for-the-most-current-timestamp/134746/6 "2018-06-07T12:18:25Z")

</div>

The most recent value `1527152400000` translates into `2018-05-24 09:00:00` from your example. What makes you think that this is not the latest time stamp?

---

<div class="post-metadata">

### Author: ![yks](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@yks](https://discuss.elastic.co/u/yks)
#### Post date: [June 8, 2018, 1:33am UTC](https://discuss.elastic.co/t/how-to-query-for-the-most-current-timestamp/134746/7 "2018-06-08T01:33:00Z")

</div>

Hi Magnus,

Yes I did not get it till you pointed out this is Unix Epoch value.

Thanks so much for the help.

---

<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 6, 2018, 1:33am UTC](https://discuss.elastic.co/t/how-to-query-for-the-most-current-timestamp/134746/8 "2018-07-06T01:33:03Z")

</div>

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