# Histogram bucket first and last record

**URL:** <https://discuss.elastic.co/t/histogram-bucket-first-and-last-record/203751>\
**Category:** Elasticsearch\
**Created:** [October 16, 2019, 6:12am UTC](https://discuss.elastic.co/t/histogram-bucket-first-and-last-record/203751 "2019-10-16T06:12:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yogesh\_BG](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yogesh_bg/32/70018_2.png) [@Yogesh\_BG](https://discuss.elastic.co/u/Yogesh_BG)\
**Post date:** [October 16, 2019, 6:12am UTC](https://discuss.elastic.co/t/histogram-bucket-first-and-last-record/203751/1 "2019-10-16T06:12:42Z")

</div>

Hi

I am using ES 6.6.0

I have time series cumulative data, i want to do histogram on the data with time being the field and get first and last records in each bucket. How can we do this?

One crude way am thinking is, apply min and max on timestamp, so that i get first and last records, but how do I extract other fields inside these two records?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 16, 2019, 12:58pm UTC](https://discuss.elastic.co/t/histogram-bucket-first-and-last-record/203751/2 "2019-10-16T12:58:46Z")

</div>

take a look at the [top hits](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/search-aggregations-metrics-top-hits-aggregation.html) aggregation

---

<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:** [November 13, 2019, 12:58pm UTC](https://discuss.elastic.co/t/histogram-bucket-first-and-last-record/203751/3 "2019-11-13T12:58:46Z")

</div>

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