# Elastic search date range aggregation not giving complete data

**URL:** <https://discuss.elastic.co/t/elastic-search-date-range-aggregation-not-giving-complete-data/20550>\
**Category:** Elasticsearch\
**Created:** [November 4, 2014, 4:33am UTC](https://discuss.elastic.co/t/elastic-search-date-range-aggregation-not-giving-complete-data/20550 "2014-11-04T04:33:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajit\_Garg](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@Rajit\_Garg](https://discuss.elastic.co/u/Rajit_Garg)\
**Post date:** [November 4, 2014, 4:33am UTC](https://discuss.elastic.co/t/elastic-search-date-range-aggregation-not-giving-complete-data/20550/1 "2014-11-04T04:33:55Z")

</div>

**I am Querying for getting aggregate data based on date\_range, like below**

```
"aggs": {
        "range": {
            "date_range": {
                "field": "sold",
                "ranges": [
                    { "from": "2014-11-01", "to": "2014-11-30" },
                    { "from": "2014-08-01", "to": "2014-08-31" } 
                ]
            }
        }
    }

```

**using this I am getting this response**

```
"aggregations": {
    "range": {
      "buckets": [
        {
          "key": "2014-08-01T00:00:00.000Z-2014-08-31T00:00:00.000Z",
          "from": 1406851200000,
          "from_as_string": "2014-08-01T00:00:00.000Z",
          "to": 1409443200000,
          "to_as_string": "2014-08-31T00:00:00.000Z",
          "doc_count": 1
        },
        {
          "key": "2014-11-01T00:00:00.000Z-2014-11-30T00:00:00.000Z",
          "from": 1414800000000,
          "from_as_string": "2014-11-01T00:00:00.000Z",
          "to": 1417305600000,
          "to_as_string": "2014-11-30T00:00:00.000Z",
          "doc_count": 2
        }
      ]
    }
  }

```

**but instead of only doc\_count, I have also required complete aggregate  
data that satisfy this range,  
is threre any way to get this..please help**

--  
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/64ae05fa-2623-4a9d-b590-be02529d6a52%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/64ae05fa-2623-4a9d-b590-be02529d6a52%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![kazoompa\_2](https://avatars.discourse-cdn.com/v4/letter/k/e47774/32.png) [@kazoompa\_2](https://discuss.elastic.co/u/kazoompa_2)\
**Post date:** [November 6, 2014, 2:57am UTC](https://discuss.elastic.co/t/elastic-search-date-range-aggregation-not-giving-complete-data/20550/2 "2014-11-06T02:57:04Z")

</div>

What do you mean by " I have also required complete aggregate data", you  
result is based on the type of the aggregation you use.

may be you can elaborate more.

Ramin

On Monday, November 3, 2014 11:33:55 PM UTC-5, Rajit Garg wrote:

> **I am Querying for getting aggregate data based on date\_range, like  
> below**
> 
> ```
> "aggs": {
> "range": {
> "date_range": {
> "field": "sold",
> "ranges": [
> { "from": "2014-11-01", "to": "2014-11-30" },
> { "from": "2014-08-01", "to": "2014-08-31" } 
> ]
> }
> }
> }
> 
> ```
> 
> **using this I am getting this response**
> 
> ```
> "aggregations": {
> "range": {
> "buckets": [
> {
> "key": "2014-08-01T00:00:00.000Z-2014-08-31T00:00:00.000Z",
> "from": 1406851200000,
> "from_as_string": "2014-08-01T00:00:00.000Z",
> "to": 1409443200000,
> "to_as_string": "2014-08-31T00:00:00.000Z",
> "doc_count": 1
> },
> {
> "key": "2014-11-01T00:00:00.000Z-2014-11-30T00:00:00.000Z",
> "from": 1414800000000,
> "from_as_string": "2014-11-01T00:00:00.000Z",
> "to": 1417305600000,
> "to_as_string": "2014-11-30T00:00:00.000Z",
> "doc_count": 2
> }
> ]
> }
> }
> 
> ```
> 
> **but instead of only doc\_count, I have also required complete aggregate  
> data that satisfy this range,  
> is threre any way to get this..please help**

--  
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/5a1b099c-76c0-402c-9f48-8f526bc24025%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5a1b099c-76c0-402c-9f48-8f526bc24025%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Rajit\_Garg](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@Rajit\_Garg](https://discuss.elastic.co/u/Rajit_Garg)\
**Post date:** [November 6, 2014, 5:26am UTC](https://discuss.elastic.co/t/elastic-search-date-range-aggregation-not-giving-complete-data/20550/3 "2014-11-06T05:26:29Z")

</div>

_Hi kazoompa,_

_Suppose I have below Data in index=cars and type=transactions_  
[  
{  
"price": 20000,  
"color": "red",  
"make": "honda",  
"sold": "2014-11-05"  
},  
{  
"price": 12000,  
"color": "green",  
"make": "toyota",  
"sold": "2014-08-19"  
},  
{  
"price": 80000,  
"color": "red",  
"make": "bmw",  
"sold": "2014-01-01"  
},  
{  
"price": 20000,  
"color": "red",  
"make": "honda",  
"sold": "2014-11-05"  
},  
{  
"price": 30000,  
"color": "green",  
"make": "ford",  
"sold": "2014-05-18"  
},  
{  
"price": 15000,  
"color": "blue",  
"make": "toyota",  
"sold": "2014-07-02"  
},  
{  
"price": 10000,  
"color": "red",  
"make": "honda",  
"sold": "2014-10-28"  
},  
{  
"price": 25000,  
"color": "blue",  
"make": "ford",  
"sold": "2014-02-12"  
},  
{  
"price": "50000",  
"color": "yellow",  
"make": "Maruti",  
"sold": "2014-10-11"  
}  
]

Now I am Querying for getting aggregate data based on date\_range, like  
below\*\*

```
"aggs": {
        "range": {
            "date_range": {
                "field": "sold",
                "ranges": [
                    { "from": "2014-11-01", "to": "2014-11-30" }
                ]
            }
        }
    }

```

i.e. date range from 1st nov to 30th nov , for this I am getting this  
output

"aggregations": {  
"range": {  
"buckets": [  
{  
"key": "2014-11-01T00:00:00.000Z-2014-11-30T00:00:00.000Z",  
"from": 1414800000000,  
"from\_as\_string": "2014-11-01T00:00:00.000Z",  
"to": 1417305600000,  
"to\_as\_string": "2014-11-30T00:00:00.000Z",  
"doc\_count": 2  
}  
]  
}  
}

from output I am getting that I have two data(doc\_count) which come under  
this range,ok

But if i have required those data which satisfies this condition or range  
like below

{  
"price": 20000,  
"color": "red",  
"make": "honda",  
"sold": "2014-11-05"  
}

{  
"price": 20000,  
"color": "red",  
"make": "honda",  
"sold": "2014-11-05"  
}

What I have required to do for this????please help???

On Thursday, November 6, 2014 8:27:05 AM UTC+5:30, kazoompa wrote:

> What do you mean by " I have also required complete aggregate data", you  
> result is based on the type of the aggregation you use.
> 
> may be you can elaborate more.
> 
> Ramin
> 
> On Monday, November 3, 2014 11:33:55 PM UTC-5, Rajit Garg wrote:
> 
> > **I am Querying for getting aggregate data based on date\_range, like  
> > below**
> > 
> > ```
> > "aggs": {
> > "range": {
> > "date_range": {
> > "field": "sold",
> > "ranges": [
> > { "from": "2014-11-01", "to": "2014-11-30" },
> > { "from": "2014-08-01", "to": "2014-08-31" } 
> > ]
> > }
> > }
> > }
> > 
> > ```
> > 
> > **using this I am getting this response**
> > 
> > ```
> > "aggregations": {
> > "range": {
> > "buckets": [
> > {
> > "key": "2014-08-01T00:00:00.000Z-2014-08-31T00:00:00.000Z",
> > "from": 1406851200000,
> > "from_as_string": "2014-08-01T00:00:00.000Z",
> > "to": 1409443200000,
> > "to_as_string": "2014-08-31T00:00:00.000Z",
> > "doc_count": 1
> > },
> > {
> > "key": "2014-11-01T00:00:00.000Z-2014-11-30T00:00:00.000Z",
> > "from": 1414800000000,
> > "from_as_string": "2014-11-01T00:00:00.000Z",
> > "to": 1417305600000,
> > "to_as_string": "2014-11-30T00:00:00.000Z",
> > "doc_count": 2
> > }
> > ]
> > }
> > }
> > 
> > ```
> > 
> > **but instead of only doc\_count, I have also required complete aggregate  
> > data that satisfy this range,  
> > is threre any way to get this..please help**

--  
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/8a51d4f1-c848-41eb-a221-ed546ab14129%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8a51d4f1-c848-41eb-a221-ed546ab14129%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, 12:51am UTC](https://discuss.elastic.co/t/elastic-search-date-range-aggregation-not-giving-complete-data/20550/4 "2017-07-06T00:51:56Z")

</div>


