# Date Histogram Aggregation is not working for me

**URL:** <https://discuss.elastic.co/t/date-histogram-aggregation-is-not-working-for-me/103034>\
**Category:** Elasticsearch\
**Created:** [October 6, 2017, 2:51pm UTC](https://discuss.elastic.co/t/date-histogram-aggregation-is-not-working-for-me/103034 "2017-10-06T14:51:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dilip\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilip_kumar/32/15459_2.png) [@Dilip\_Kumar](https://discuss.elastic.co/u/Dilip_Kumar)\
**Post date:** [October 6, 2017, 2:51pm UTC](https://discuss.elastic.co/t/date-histogram-aggregation-is-not-working-for-me/103034/1 "2017-10-06T14:51:43Z")

</div>

Please help me to es query I have store data in es as  
{  
"i": [  
{  
"ap": "com.touchtype.swiftkey",  
"t": "1507284964"  
},  
{  
"ap": "com.sly.sangam.mediametadatareader",  
"t": "1506398555"  
},  
{  
"ap": "com.flipkart.android",  
"t": "1505733513"  
},  
{  
"ap": "com.google.android.apps.inputmethod.hindi",  
"t": "1507284964"  
},  
{  
"ap": "com.mfashiongallery.emag",  
"t": "1505733231"  
},  
{  
"ap": "com.google.android.instantapps.supervisor",  
"t": "1505734613"  
},  
{  
"ap": "com.duokan.phone.remotecontroller",  
"t": "1505733237"  
},  
{  
"ap": "com.zingtillion",  
"t": "1507284921"  
},  
{  
"ap": "com.miui.klo.bugreport",  
"t": "1507284964"  
},  
{  
"ap": "com.zing.ultronone",  
"t": "1505982478"  
},  
{  
"ap": "com.swiftkey.swiftkeyconfigurator",  
"t": "1507284964"  
},  
{  
"ap": "com.facebook.katana",  
"t": "1507284964"  
},  
{  
"ap": "[com.mi.global.shop](http://com.mi.global.shop)",  
"t": "1505733219"  
},  
{  
"ap": "com.swiftkey.languageprovider",  
"t": "1507284964"  
},  
{  
"ap": "cn.wps.moffice\_eng",  
"t": "1505733250"  
}  
],  
"id": "1171533212255571",  
"dt": "2017-10-06T18:16:04"  
}

Now try to fetch hourly count but getting equal count(15) in each bucket, i need only those count related to that date (i.t)

"size": 0,  
"aggs": {  
"final\_bucket": {  
"filter": {  
"term": {  
"zid": "1171533212255571"  
}  
},  
"aggs": {  
"group\_by\_field1": {  
"date\_histogram": {  
"field": "i.t",  
"interval": "hour",  
"min\_doc\_count": 1,  
"format": "yyyy-MM-dd hh:mm a",  
"order" : { "\_key" : "asc" }  
},  
"aggs": {  
"field\_count": {  
"cardinality": {  
"field": "i.ap"  
}  
}  
}  
}  
}  
}  
}

===================Output=============================

"aggregations": {  
"final\_bucket": {  
"doc\_count": 1,  
"group\_by\_field1": {  
"buckets": [  
{  
"key\_as\_string": "2017-09-18 11:00 AM",  
"key": 1505732400000,  
"doc\_count": 1,  
"field\_count": {  
"value": 15  
}  
},  
{  
"key\_as\_string": "2017-09-21 08:00 AM",  
"key": 1505980800000,  
"doc\_count": 1,  
"field\_count": {  
"value": 15  
}  
},  
{  
"key\_as\_string": "2017-09-26 04:00 AM",  
"key": 1506398400000,  
"doc\_count": 1,  
"field\_count": {  
"value": 15  
}  
},  
{  
"key\_as\_string": "2017-10-06 10:00 AM",  
"key": 1507284000000,  
"doc\_count": 1,  
"field\_count": {  
"value": 15  
}  
}  
]  
}  
}  
}  
}

---

<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 3, 2017, 2:52pm UTC](https://discuss.elastic.co/t/date-histogram-aggregation-is-not-working-for-me/103034/2 "2017-11-03T14:52:29Z")

</div>

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