# Can we match both date range aggregation count and date range query count

**URL:** https://discuss.elastic.co/t/can-we-match-both-date-range-aggregation-count-and-date-range-query-count/164093
**Category:** Elasticsearch
**Created:** [January 14, 2019, 7:16am UTC](https://discuss.elastic.co/t/can-we-match-both-date-range-aggregation-count-and-date-range-query-count/164093 "2019-01-14T07:16:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![prasad.ram1431](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@prasad.ram1431](https://discuss.elastic.co/u/prasad.ram1431)
#### Post date: [January 14, 2019, 7:16am UTC](https://discuss.elastic.co/t/can-we-match-both-date-range-aggregation-count-and-date-range-query-count/164093/1 "2019-01-14T07:16:02Z")

</div>

Hi All,

I need some clarification, whether I am doing correct or wrong. I have below two queries.  
Query1:

> "aggs": {  
> "previous\_aggr": {  
> "nested": {  
> "path": "prevFin"  
> },  
> "aggs": {  
> "prev\_aggr": {  
> "date\_range": {  
> "field": "prevFin.statDate",  
> "ranges": [  
> {  
> "from": "2015-01-01",  
> "to": "2015-12-31"  
> }  
> ]  
> }  
> }  
> }  
> }  
> }

Response:

> "prev\_aggr": {  
> "buckets": [  
> {  
> "key": "2015-01-01-2015-12-31",  
> "from": 1420070400000,  
> "from\_as\_string": "2015-01-01",  
> "to": 1451520000000,  
> "to\_as\_string": "2015-12-31",  
> **"doc\_count": 6509**  
> }  
> ]  
> }

Query2:

> "query": {  
> "nested": {  
> "path": "prevFin",  
> "query": {  
> "range": {  
> "prevFin.statDate": {  
> "gte": "2015-01-01",  
> "lt": "2015-12-31"  
> }  
> }  
> }  
> }  
> }

Response:  
**"total": 6503**  
I came to know from ES doc that, To is excluded from Range Aggregation query.  
But how to get the same count for both Date Range Query and Date Range Aggregation Query.  
Can we get the same count for both queries.  
Could Someone please explain this.

Thanks,  
Ram

---

<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: [February 11, 2019, 7:16am UTC](https://discuss.elastic.co/t/can-we-match-both-date-range-aggregation-count-and-date-range-query-count/164093/2 "2019-02-11T07:16:05Z")

</div>

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