# ElasticSearch - Latest record per day per ID from elastic

**URL:** https://discuss.elastic.co/t/elasticsearch-latest-record-per-day-per-id-from-elastic/262993
**Category:** Elasticsearch
**Created:** [February 2, 2021, 1:55pm UTC](https://discuss.elastic.co/t/elasticsearch-latest-record-per-day-per-id-from-elastic/262993 "2021-02-02T13:55:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![prashantmalik](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@prashantmalik](https://discuss.elastic.co/u/prashantmalik)
#### Post date: [February 2, 2021, 1:55pm UTC](https://discuss.elastic.co/t/elasticsearch-latest-record-per-day-per-id-from-elastic/262993/1 "2021-02-02T13:55:13Z")

</div>

I have index in Elsaticsearch of records of form:

```auto
Record{
  Timestamp;
  Id;
  .
  .}

```

It has multiple records for ID per day.

I want to fetch latest record per Id per day. Can you please help me with such query?

Example- Records :

```auto
R1 -> Id=A1, Timestamp = 2021-02-02_12:00:00, other fields
R2 -> Id=A1, Timestamp = 2021-02-02_11:00:00, other fields
R3 -> Id=A2, Timestamp = 2021-02-02_10:30:00, other fields
R4 -> Id=A2, Timestamp = 2021-02-02_10:00:00, other fields
R5 -> Id=A1, Timestamp = 2021-02-01_13:00:00, other fields
R6 -> Id=A1, Timestamp = 2021-02-01_11:00:00, other fields
R7 -> Id=A2, Timestamp = 2021-02-01_11:30:00, other fields
R8 -> Id=A2, Timestamp = 2021-02-01_10:00:00, other fields

```

Required output: Complete records : R1, R3, R5, R7

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [February 2, 2021, 2:03pm UTC](https://discuss.elastic.co/t/elasticsearch-latest-record-per-day-per-id-from-elastic/262993/2 "2021-02-02T14:03:39Z")

</div>

Hi Prashant.  
See [this post](https://discuss.elastic.co/t/get-last-document-string-value-in-each-bucket/260013/2)

---

<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: [March 2, 2021, 2:04pm UTC](https://discuss.elastic.co/t/elasticsearch-latest-record-per-day-per-id-from-elastic/262993/3 "2021-03-02T14:04:20Z")

</div>

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