# Unable to set bounds to date histogram query

**URL:** https://discuss.elastic.co/t/unable-to-set-bounds-to-date-histogram-query/18625
**Category:** Elasticsearch
**Created:** [July 12, 2014, 4:34pm UTC](https://discuss.elastic.co/t/unable-to-set-bounds-to-date-histogram-query/18625 "2014-07-12T16:34:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![K\_Samanth\_Kumar\_Redd](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@K\_Samanth\_Kumar\_Redd](https://discuss.elastic.co/u/K_Samanth_Kumar_Redd)
#### Post date: [July 12, 2014, 4:34pm UTC](https://discuss.elastic.co/t/unable-to-set-bounds-to-date-histogram-query/18625/1 "2014-07-12T16:34:49Z")

</div>

Hi,

I am using elasticsearch for last 3 months. It is really good for searching  
the billions of docs.  
I have created an 'order' index and the document contains the 'orders'  
array. Please find the use case below.

Use Case: Get orders created in terms of Price and Count over a period of  
time month wise.  
Ex:- I want the result only for last one year. I tried the following query.  
It is giving the result, but I am getting for all the years instead of last  
one year..

Can anybody please help me?

{  
"aggregations" : {  
"orders" : {  
"nested" : {  
"path" : "orders"  
},  
"aggregations" : {  
"date\_histo" : {  
"date\_histogram" : {  
"field" : "orders.created\_date",  
"interval" : "1M",  
"extended\_bounds" : {  
"min" : "now-1y/d",  
"max" : "now"  
}  
},  
"aggregations" : {  
"tot\_size" : {  
"sum" : {  
"field" : "orders.price"  
}  
}  
}  
}  
}  
}  
}  
}

Thanks & Regards,  
Samanth

--  
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/b66904a8-2906-4fb3-ad86-fc648a40f57b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b66904a8-2906-4fb3-ad86-fc648a40f57b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)
#### Post date: [July 12, 2014, 5:03pm UTC](https://discuss.elastic.co/t/unable-to-set-bounds-to-date-histogram-query/18625/2 "2014-07-12T17:03:54Z")

</div>

Hello Samnath ,

You are looking at the wrong area.  
Aggregation merely aggregates results from your query.  
You need to build a query which will define what would be result.  
You need to use the range query -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Thanks  
Vineeth

On Sat, Jul 12, 2014 at 10:04 PM, K.Samanth Kumar Reddy \<  
[samanthkumar.k@gmail.com](mailto:samanthkumar.k@gmail.com)\> wrote:

> Hi,
> 
> I am using elasticsearch for last 3 months. It is really good for  
> searching the billions of docs.  
> I have created an 'order' index and the document contains the 'orders'  
> array. Please find the use case below.
> 
> Use Case: Get orders created in terms of Price and Count over a period of  
> time month wise.  
> Ex:- I want the result only for last one year. I tried the following  
> query. It is giving the result, but I am getting for all the years instead  
> of last one year..
> 
> Can anybody please help me?
> 
> {  
> "aggregations" : {  
> "orders" : {  
> "nested" : {  
> "path" : "orders"  
> },  
> "aggregations" : {  
> "date\_histo" : {  
> "date\_histogram" : {  
> "field" : "orders.created\_date",  
> "interval" : "1M",  
> "extended\_bounds" : {  
> "min" : "now-1y/d",  
> "max" : "now"  
> }  
> },  
> "aggregations" : {  
> "tot\_size" : {  
> "sum" : {  
> "field" : "orders.price"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> Thanks & Regards,  
> Samanth
> 
> --  
> 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/b66904a8-2906-4fb3-ad86-fc648a40f57b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b66904a8-2906-4fb3-ad86-fc648a40f57b%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/b66904a8-2906-4fb3-ad86-fc648a40f57b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/b66904a8-2906-4fb3-ad86-fc648a40f57b%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/CAGdPd5m0%3Dh96VFhNW3wcWmXiMRDuDoN2Mn\_u6J9K3HPsVhOa5w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5m0%3Dh96VFhNW3wcWmXiMRDuDoN2Mn_u6J9K3HPsVhOa5w%40mail.gmail.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:16am UTC](https://discuss.elastic.co/t/unable-to-set-bounds-to-date-histogram-query/18625/3 "2017-07-06T01:16:17Z")

</div>


