# Date\_histogram not returning key\_as\_string

**URL:** <https://discuss.elastic.co/t/date-histogram-not-returning-key-as-string/17935>\
**Category:** Elasticsearch\
**Created:** [June 5, 2014, 6:06pm UTC](https://discuss.elastic.co/t/date-histogram-not-returning-key-as-string/17935 "2014-06-05T18:06:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Heikell](https://avatars.discourse-cdn.com/v4/letter/t/f4b2a3/32.png) [@Tim\_Heikell](https://discuss.elastic.co/u/Tim_Heikell)\
**Post date:** [June 5, 2014, 6:06pm UTC](https://discuss.elastic.co/t/date-histogram-not-returning-key-as-string/17935/1 "2014-06-05T18:06:52Z")

</div>

Sorry for the noob question, but is there some setting I am missing? It's  
not clear to me why I'm not getting a key\_as\_string field in my results.  
I'm running v1.1.0, here is my search:

GET /\_all/\_search  
{  
"aggs": {  
"totalsByHour": {  
"date\_histogram": {  
"field": "sessionStartTime",  
"interval": "day",  
"format": "yyyy-MM-dd"  
}  
}  
}  
}

and here are my results:

"aggregations": {  
"totalsByHour": {  
"buckets": [  
{  
"key": 1401667200000,  
"doc\_count": 15973  
},  
{  
"key": 1401753600000,  
"doc\_count": 11996  
},  
{  
"key": 1401840000000,  
"doc\_count": 14  
},  
{  
"key": 1401926400000,  
"doc\_count": 4031  
}  
]  
}  
}

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0acca250-ab7f-48a8-a73a-648f7f544dcd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0acca250-ab7f-48a8-a73a-648f7f544dcd%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 16, 2014, 12:38pm UTC](https://discuss.elastic.co/t/date-histogram-not-returning-key-as-string/17935/2 "2014-06-16T12:38:36Z")

</div>

Hey,

can you create a full gist to reproduce this? Should work out of the box  
(dont see anything wrong here), also on 1.1.0

--Alex

On Thu, Jun 5, 2014 at 8:06 PM, Tim Heikell [tim.heikell@heapsylon.com](mailto:tim.heikell@heapsylon.com)  
wrote:

> Sorry for the noob question, but is there some setting I am missing? It's  
> not clear to me why I'm not getting a key\_as\_string field in my results.  
> I'm running v1.1.0, here is my search:
> 
> GET /\_all/\_search  
> {  
> "aggs": {  
> "totalsByHour": {  
> "date\_histogram": {  
> "field": "sessionStartTime",  
> "interval": "day",  
> "format": "yyyy-MM-dd"  
> }  
> }  
> }  
> }
> 
> and here are my results:
> 
> "aggregations": {  
> "totalsByHour": {  
> "buckets": [  
> {  
> "key": 1401667200000,  
> "doc\_count": 15973  
> },  
> {  
> "key": 1401753600000,  
> "doc\_count": 11996  
> },  
> {  
> "key": 1401840000000,  
> "doc\_count": 14  
> },  
> {  
> "key": 1401926400000,  
> "doc\_count": 4031  
> }  
> ]  
> }  
> }
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/0acca250-ab7f-48a8-a73a-648f7f544dcd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0acca250-ab7f-48a8-a73a-648f7f544dcd%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/0acca250-ab7f-48a8-a73a-648f7f544dcd%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0acca250-ab7f-48a8-a73a-648f7f544dcd%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM\_aj0JhVsn6e7qxSF6VuLG8%2BnE3x5RxONWWFuLstz8GkQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_aj0JhVsn6e7qxSF6VuLG8%2BnE3x5RxONWWFuLstz8GkQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Tim\_Heikell](https://avatars.discourse-cdn.com/v4/letter/t/f4b2a3/32.png) [@Tim\_Heikell](https://discuss.elastic.co/u/Tim_Heikell)\
**Post date:** [June 16, 2014, 3:21pm UTC](https://discuss.elastic.co/t/date-histogram-not-returning-key-as-string/17935/3 "2014-06-16T15:21:10Z")

</div>

Thank you Alexander, but I got it figured out. I was storing  
sessionStartTime as a Unix timestamp but did not provide any mapping, so  
the field type was set to be a double. Once I explicitly mapped  
sessionStartTime to be a date my query results started including the  
key\_as\_string field.

Tim

On Monday, June 16, 2014 5:38:42 AM UTC-7, Alexander Reelsen wrote:

> Hey,
> 
> can you create a full gist to reproduce this? Should work out of the box  
> (dont see anything wrong here), also on 1.1.0
> 
> --Alex
> 
> On Thu, Jun 5, 2014 at 8:06 PM, Tim Heikell \<[tim.h...@heapsylon.com](mailto:tim.h...@heapsylon.com)  
> \<javascript:\>\> wrote:
> 
> > Sorry for the noob question, but is there some setting I am missing? It's  
> > not clear to me why I'm not getting a key\_as\_string field in my results.  
> > I'm running v1.1.0, here is my search:
> > 
> > GET /\_all/\_search  
> > {  
> > "aggs": {  
> > "totalsByHour": {  
> > "date\_histogram": {  
> > "field": "sessionStartTime",  
> > "interval": "day",  
> > "format": "yyyy-MM-dd"  
> > }  
> > }  
> > }  
> > }
> > 
> > and here are my results:
> > 
> > "aggregations": {  
> > "totalsByHour": {  
> > "buckets": [  
> > {  
> > "key": 1401667200000,  
> > "doc\_count": 15973  
> > },  
> > {  
> > "key": 1401753600000,  
> > "doc\_count": 11996  
> > },  
> > {  
> > "key": 1401840000000,  
> > "doc\_count": 14  
> > },  
> > {  
> > "key": 1401926400000,  
> > "doc\_count": 4031  
> > }  
> > ]  
> > }  
> > }
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/0acca250-ab7f-48a8-a73a-648f7f544dcd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0acca250-ab7f-48a8-a73a-648f7f544dcd%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/0acca250-ab7f-48a8-a73a-648f7f544dcd%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0acca250-ab7f-48a8-a73a-648f7f544dcd%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2fbead94-8471-43e9-9544-9e23f3d2d1b3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2fbead94-8471-43e9-9544-9e23f3d2d1b3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:22am UTC](https://discuss.elastic.co/t/date-histogram-not-returning-key-as-string/17935/4 "2017-07-06T01:22:05Z")

</div>


