# Get Last Document Stored based on the Unique Field Type

**URL:** <https://discuss.elastic.co/t/get-last-document-stored-based-on-the-unique-field-type/122192>\
**Category:** Elasticsearch\
**Created:** [March 2, 2018, 5:21am UTC](https://discuss.elastic.co/t/get-last-document-stored-based-on-the-unique-field-type/122192 "2018-03-02T05:21:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul1243](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@paul1243](https://discuss.elastic.co/u/paul1243)\
**Post date:** [March 2, 2018, 5:21am UTC](https://discuss.elastic.co/t/get-last-document-stored-based-on-the-unique-field-type/122192/1 "2018-03-02T05:21:41Z")

</div>

Hi,  
I have the documents storing on elastic search every hour and have the index as (testing-2018-03-12) which has some fields.  
How do I return only the last documents based on a field ?

Example:

Doc1:  
User: Paul  
age: 34  
Hours Logged: 8  
@timestamp: \*\*\*\*

Doc2:  
User: Paul  
age: 34  
Hours Logged: 8.5  
@timestamp: \*\*\*\*

Doc3:  
User: Kim  
age: 23  
Hours Logged: 4  
@timestamp: \*\*\*\*

Doc4:  
User: Kim  
age: 23  
Hours Logged: 3  
@timestamp: \*\*\*\*

How do I return the latest document for all the Users?

---

<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 30, 2018, 5:33am UTC](https://discuss.elastic.co/t/get-last-document-stored-based-on-the-unique-field-type/122192/2 "2018-03-30T05:33:01Z")

</div>

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