# Date histogram error

**URL:** https://discuss.elastic.co/t/date-histogram-error/295155
**Category:** Elasticsearch
**Created:** [January 23, 2022, 6:31pm UTC](https://discuss.elastic.co/t/date-histogram-error/295155 "2022-01-23T18:31:33Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)
#### Post date: [January 24, 2022, 11:53pm UTC](https://discuss.elastic.co/t/date-histogram-error/295155/8 "2022-01-24T23:53:00Z")

</div>

Is there some difference from the previous topic?

> [@Getting every 2nd element from \_source](https://discuss.elastic.co/t/getting-every-2nd-element-from-source/295123/4):
>
> So the true problem is the necessary size for query could be hundreds of thousands and too wasteful. Then you can use [Date histogram aggregation | Elasticsearch Guide [7.16] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html) with [Top hits aggregation | Elasticsearch Guide [7.16] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html). Top hit with size=1 and sort by date, you can get last (or first) documents in the date-histo buckets.

If you need some last metrics other than last document, you can use top metrics aggregation sorted by time stamp.

> **[Top metrics aggregation | Elasticsearch Guide \[master\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-metrics-top-metrics.html)**

---

_[View the full topic](https://discuss.elastic.co/t/date-histogram-error/295155)._
