# Date aggregation query based out of a range

**URL:** <https://discuss.elastic.co/t/date-aggregation-query-based-out-of-a-range/255895>\
**Category:** Elasticsearch\
**Created:** [November 18, 2020, 8:15pm UTC](https://discuss.elastic.co/t/date-aggregation-query-based-out-of-a-range/255895 "2020-11-18T20:15:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alok\_Ranjan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alok_ranjan/32/79255_2.png) [@Alok\_Ranjan](https://discuss.elastic.co/u/Alok_Ranjan)\
**Post date:** [November 18, 2020, 8:15pm UTC](https://discuss.elastic.co/t/date-aggregation-query-based-out-of-a-range/255895/1 "2020-11-18T20:15:13Z")

</div>

Hi All,  
I have a simple requirement to get the aggregated result as per the posted date like documents posted any day, today, less than 7 days, less than 30 days, or greater than 30 days.  
I wrote a simple date range query which is returning the result but the doc count is 0. It seems I am missing something.  
"aggs": {  
"postedDate": {  
"date\_range": {  
"field": "publishDate",  
"ranges": [  
{  
"from": "now-1825d/d",  
"to": "now/d",  
"key":"Any"  
},  
{  
"from": "now-1d/d",  
"to": "now/d",  
"key":"Today"  
},  
{  
"from": "now-7d/d",  
"to": "now/d",  
"key":"LESS\_THAN\_7"  
},  
{  
"from": "now-30d/d",  
"to": "now/d",  
"key":"LESS\_THAN\_30"  
},  
{  
"to": "now-30d/d",  
"key":"GREATER\_THAN\_30"  
}  
]  
}  
}  
}  
Any pointer to write a correct query will be helpful.

---

<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:** [December 16, 2020, 8:15pm UTC](https://discuss.elastic.co/t/date-aggregation-query-based-out-of-a-range/255895/2 "2020-12-16T20:15:15Z")

</div>

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