# How to take only last 20 records of the document in Visualization?

**URL:** <https://discuss.elastic.co/t/how-to-take-only-last-20-records-of-the-document-in-visualization/215117>\
**Category:** Kibana\
**Created:** [January 15, 2020, 10:52am UTC](https://discuss.elastic.co/t/how-to-take-only-last-20-records-of-the-document-in-visualization/215117 "2020-01-15T10:52:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Utshab\_Saha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/utshab_saha/32/58146_2.png) [@Utshab\_Saha](https://discuss.elastic.co/u/Utshab_Saha)\
**Post date:** [January 15, 2020, 10:52am UTC](https://discuss.elastic.co/t/how-to-take-only-last-20-records-of-the-document-in-visualization/215117/1 "2020-01-15T10:52:05Z")

</div>

I want to count of hits w.r.t the **datetime** in visualization but while I use visualization tool to build the chart It applies on the whole document.

So when I plot the data with 10 objects (size of the bucket) in Asc order it sorts from the whole document and plots it bellow is the screen shot

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/b/5bd550173aff2f48c52068da5f76c6404276ec9d.png)

And if I sort it in Desc order it applies on the whole document and shows such result

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/a/0a27083ad5aa214d20a268694e904028243b2702.png)

Hence I am not able to fetch **todays** records.

Please help  
Thanks and Regards

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [January 16, 2020, 3:37pm UTC](https://discuss.elastic.co/t/how-to-take-only-last-20-records-of-the-document-in-visualization/215117/2 "2020-01-16T15:37:15Z")

</div>

Hi there,

if you want that type of graph you don't need a Terms aggregation but a Date Histogram aggregation on a date type field.

---

<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:** [February 13, 2020, 3:37pm UTC](https://discuss.elastic.co/t/how-to-take-only-last-20-records-of-the-document-in-visualization/215117/3 "2020-02-13T15:37:19Z")

</div>

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