# Date doesn't seem to work with date\_histogram

**URL:** https://discuss.elastic.co/t/date-doesnt-seem-to-work-with-date-histogram/129515
**Category:** Elasticsearch
**Created:** [April 25, 2018, 2:45pm UTC](https://discuss.elastic.co/t/date-doesnt-seem-to-work-with-date-histogram/129515 "2018-04-25T14:45:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![himberjack](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/himberjack/32/48211_2.png) [@himberjack](https://discuss.elastic.co/u/himberjack)
#### Post date: [April 25, 2018, 2:45pm UTC](https://discuss.elastic.co/t/date-doesnt-seem-to-work-with-date-histogram/129515/1 "2018-04-25T14:45:17Z")

</div>

We've made a template that has:

> "properties": {  
> "timestamp": {  
> "type": "date",  
> "format": "epoch\_second"  
> },

When reading the \_mapping we get:

> "timestamp": {  
> "type": "long"  
> }

We are unable to do date\_histogram, as it aggregates by all and not by day as it should be:

> "date\_histogram": {  
> "field": "timestamp",  
> "interval": "day"  
> }

Is the "long" time ok? How can we histogram on this?

---

<div class="post-metadata">

### Author: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [April 27, 2018, 2:03pm UTC](https://discuss.elastic.co/t/date-doesnt-seem-to-work-with-date-histogram/129515/2 "2018-04-27T14:03:53Z")

</div>

It sounds like your template is not being applied correctly, or some data was indexed before the template was put in place. I'd try to get that sorted so that the data is properly mapped as a date. Internally it's just a long, but having correct mapping will make your life a lot easier.

Perhaps the syntax on your template is incorrect, or not matching the right pattern? Can you verify that it was in place before any data was indexed?

---

<div class="post-metadata">

### Author: ![himberjack](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/himberjack/32/48211_2.png) [@himberjack](https://discuss.elastic.co/u/himberjack)
#### Post date: [April 29, 2018, 7:25pm UTC](https://discuss.elastic.co/t/date-doesnt-seem-to-work-with-date-histogram/129515/3 "2018-04-29T19:25:01Z")

</div>

Yes you were right! Thanks!

---

<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: [May 27, 2018, 7:25pm UTC](https://discuss.elastic.co/t/date-doesnt-seem-to-work-with-date-histogram/129515/4 "2018-05-27T19:25:03Z")

</div>

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