# Date Histogram Facets

**URL:** <https://discuss.elastic.co/t/date-histogram-facets/12542>\
**Category:** Elasticsearch\
**Created:** [June 25, 2013, 6:26pm UTC](https://discuss.elastic.co/t/date-histogram-facets/12542 "2013-06-25T18:26:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_H](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christopher_h/32/2259_2.png) [@Christopher\_H](https://discuss.elastic.co/u/Christopher_H)\
**Post date:** [June 25, 2013, 6:26pm UTC](https://discuss.elastic.co/t/date-histogram-facets/12542/1 "2013-06-25T18:26:34Z")

</div>

I am currently storing dates in the format: yyyyMMdd'T'HH:mm:ss. (same  
format used in the overview video) So my current time looks like this:  
20130625T11:20:00.

My mapping for the date field looks like this:  
"date" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},

My date\_histogram search is this:  
{  
"query": {  
"match\_all": {}  
},  
"facets": {  
"histo1": {  
"date\_histogram": {  
"field": "date",  
"interval": "day"  
}  
}  
}  
}

I am trying to use the date\_histogram and I seem to get very weird  
timestamps. All my dates are just a few days old, so there is no timestamp  
that is older than the 20th of June, 2013 nor is their any timestamps that  
are after todays date. However in the date histogram facet results I get  
are like this:

- {
  - time: 634245916608000000
  - count: 3  
}

- {
  - time: 634245979766400000
  - count: 15  
}

- {
  - time: 634246042838400000
  - count: 6  
}

- {

Any idea as to why the timestamps are so far in the future? A range query  
works pretty well, but not the date\_histogram.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [June 26, 2013, 6:52am UTC](https://discuss.elastic.co/t/date-histogram-facets/12542/2 "2013-06-26T06:52:49Z")

</div>

Hey,

I think your date format does not match 'dateOptionalTime', see

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Can you set it explicitely in the mapping or try with a real ISO8601 date?

--Alex

On Tue, Jun 25, 2013 at 8:26 PM, Christopher H [cphartfield@gmail.com](mailto:cphartfield@gmail.com)wrote:

> I am currently storing dates in the format: yyyyMMdd'T'HH:mm:ss. (same  
> format used in the overview video) So my current time looks like this:  
> 20130625T11:20:00.
> 
> My mapping for the date field looks like this:  
> "date" : {  
> "type" : "date",  
> "format" : "dateOptionalTime"  
> },
> 
> My date\_histogram search is this:  
> {  
> "query": {  
> "match\_all": {}  
> },  
> "facets": {  
> "histo1": {  
> "date\_histogram": {  
> "field": "date",  
> "interval": "day"  
> }  
> }  
> }  
> }
> 
> I am trying to use the date\_histogram and I seem to get very weird  
> timestamps. All my dates are just a few days old, so there is no timestamp  
> that is older than the 20th of June, 2013 nor is their any timestamps that  
> are after todays date. However in the date histogram facet results I get  
> are like this:
> 
> - {
> - time: 634245916608000000
> - count: 3  
> }
> 
> - {
> - time: 634245979766400000
> - count: 15  
> }
> 
> - {
> - time: 634246042838400000
> - count: 6  
> }
> 
> - {
> 
> Any idea as to why the timestamps are so far in the future? A range query  
> works pretty well, but not the date\_histogram.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:29am UTC](https://discuss.elastic.co/t/date-histogram-facets/12542/3 "2017-07-06T02:29:27Z")

</div>


