# How to get first file and last file in data?

**URL:** <https://discuss.elastic.co/t/how-to-get-first-file-and-last-file-in-data/311945>\
**Category:** Kibana\
**Created:** [August 11, 2022, 3:48pm UTC](https://discuss.elastic.co/t/how-to-get-first-file-and-last-file-in-data/311945 "2022-08-11T15:48:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MLsuper](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MLsuper](https://discuss.elastic.co/u/MLsuper)\
**Post date:** [August 11, 2022, 3:48pm UTC](https://discuss.elastic.co/t/how-to-get-first-file-and-last-file-in-data/311945/1 "2022-08-11T15:48:25Z")

</div>

I have a index pattern with data with files for every business day(i have a run time field named business time/day) which is the business day and time everyday.

Now I want to show a visualization/dashboard to get the batch duration(I have a field) on the first file on a daily basis(every day in a certain time in a business time) and the last file in the same business day.

So I just want the first file and last file loaded every day on a daily basis(which is in the data everyday)

How would I approach this? a scripted field? Not sure? thank you!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 12, 2022, 1:31am UTC](https://discuss.elastic.co/t/how-to-get-first-file-and-last-file-in-data/311945/2 "2022-08-12T01:31:23Z")

</div>

You could do that with a [top hits aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/8.3/search-aggregations-metrics-top-hits-aggregation.html), and sort asc/desc on timestamp to get each one.

---

<div class="post-metadata">

**Author:** ![MLsuper](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MLsuper](https://discuss.elastic.co/u/MLsuper)\
**Post date:** [August 12, 2022, 3:22pm UTC](https://discuss.elastic.co/t/how-to-get-first-file-and-last-file-in-data/311945/4 "2022-08-12T15:22:38Z")

</div>

thank you, how would I use this for kibana dashboards/visulizations?

---

<div class="post-metadata">

**Author:** ![MLsuper](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MLsuper](https://discuss.elastic.co/u/MLsuper)\
**Post date:** [August 16, 2022, 7:47pm UTC](https://discuss.elastic.co/t/how-to-get-first-file-and-last-file-in-data/311945/5 "2022-08-16T19:47:18Z")

</div>

is it possible to show this in a dashboard visulization in kibana?

---

<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:** [September 13, 2022, 7:48pm UTC](https://discuss.elastic.co/t/how-to-get-first-file-and-last-file-in-data/311945/6 "2022-09-13T19:48:07Z")

</div>

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