# Custom date histogram interval

**URL:** https://discuss.elastic.co/t/custom-date-histogram-interval/18536
**Category:** Elasticsearch
**Created:** [July 8, 2014, 5:55pm UTC](https://discuss.elastic.co/t/custom-date-histogram-interval/18536 "2014-07-08T17:55:58Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Gabe\_Gorelick\_Feldma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabe_gorelick_feldma/32/1423_2.png) [@Gabe\_Gorelick\_Feldma](https://discuss.elastic.co/u/Gabe_Gorelick_Feldma)
#### Post date: [July 8, 2014, 5:55pm UTC](https://discuss.elastic.co/t/custom-date-histogram-interval/18536/1 "2014-07-08T17:55:58Z")

</div>

Is there any way to use a custom interval with date histograms (either  
facets or aggregations)? For example, something like

```
{
  "date_histogram": {
    "field": "date",
    "interval": "fiscalYear"
  }
}

```

Obviously, you can always use a regular histogram, but then the client  
would have to manage all the complexities that come with dealing with time.

--  
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/37ef7076-f68f-49ff-bd48-3d8431a576d1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%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 8, 2014, 9:09pm UTC](https://discuss.elastic.co/t/custom-date-histogram-interval/18536/2 "2014-07-08T21:09:25Z")

</div>

Hello Gabe ,

Please elaborate on what you mean by custom interval .

Thanks  
Vineeth

On Tue, Jul 8, 2014 at 11:25 PM, Gabe Gorelick-Feldman \<  
[gabegorelick@gmail.com](mailto:gabegorelick@gmail.com)\> wrote:

> Is there any way to use a custom interval with date histograms (either  
> facets or aggregations)? For example, something like
> 
> ```
> {
> "date_histogram": {
> "field": "date",
> "interval": "fiscalYear"
> }
> }
> 
> ```
> 
> Obviously, you can always use a regular histogram, but then the client  
> would have to manage all the complexities that come with dealing with time.
> 
> --  
> 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/37ef7076-f68f-49ff-bd48-3d8431a576d1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%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/CAGdPd5kN788jMHficcQbHa%2BtEsFkn34h%3DUVhqEeRG\_NJx\_gguA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kN788jMHficcQbHa%2BtEsFkn34h%3DUVhqEeRG_NJx_gguA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Gabe\_Gorelick\_Feldma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabe_gorelick_feldma/32/1423_2.png) [@Gabe\_Gorelick\_Feldma](https://discuss.elastic.co/u/Gabe_Gorelick_Feldma)
#### Post date: [July 8, 2014, 9:19pm UTC](https://discuss.elastic.co/t/custom-date-histogram-interval/18536/3 "2014-07-08T21:19:07Z")

</div>

Sure. According to the docs [1], the available expressions for  
date\_histogram interval are year, quarter, month, week, day, hour, minute,  
second. But what if you want to rollup by another interval that's not  
supported, like decade or millisecond? I was just wondering if there was  
maybe a way to write a plugin for such custom intervals.

Specifically, I need a CDC MMWR week [2] interval, which is similar to ISO  
week (which I assume is what elasticsearch uses), but not exactly the same.

[1] [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html)  
[2] [http://wwwn.cdc.gov/nndss/document/MMWR\_Week\_overview.pdf](http://wwwn.cdc.gov/nndss/document/MMWR_Week_overview.pdf)

On Tuesday, July 8, 2014 5:09:39 PM UTC-4, vineeth mohan wrote:

> Hello Gabe ,
> 
> Please elaborate on what you mean by custom interval .
> 
> Thanks  
> Vineeth
> 
> On Tue, Jul 8, 2014 at 11:25 PM, Gabe Gorelick-Feldman \<  
> [gabego...@gmail.com](mailto:gabego...@gmail.com) \<javascript:\>\> wrote:
> 
> > Is there any way to use a custom interval with date histograms (either  
> > facets or aggregations)? For example, something like
> > 
> > ```
> > {
> > "date_histogram": {
> > "field": "date",
> > "interval": "fiscalYear"
> > }
> > }
> > 
> > ```
> > 
> > Obviously, you can always use a regular histogram, but then the client  
> > would have to manage all the complexities that come with dealing with time.
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%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/b8617abb-ed9e-4fff-95f6-cb81a3def727%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%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 8, 2014, 9:29pm UTC](https://discuss.elastic.co/t/custom-date-histogram-interval/18536/4 "2014-07-08T21:29:47Z")

</div>

Hello Gabe ,

You can mention the range as 1.5h or 2w and all -

> **[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.

Hope that might help your cause.

Thanks  
Vineeth

On Wed, Jul 9, 2014 at 2:49 AM, Gabe Gorelick-Feldman \<  
[gabegorelick@gmail.com](mailto:gabegorelick@gmail.com)\> wrote:

> Sure. According to the docs [1], the available expressions for  
> date\_histogram interval are year, quarter, month, week, day, hour, minute,  
> second. But what if you want to rollup by another interval that's not  
> supported, like decade or millisecond? I was just wondering if there was  
> maybe a way to write a plugin for such custom intervals.
> 
> Specifically, I need a CDC MMWR week [2] interval, which is similar to ISO  
> week (which I assume is what elasticsearch uses), but not exactly the same.
> 
> [1]  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html)  
> [2] [http://wwwn.cdc.gov/nndss/document/MMWR\_Week\_overview.pdf](http://wwwn.cdc.gov/nndss/document/MMWR_Week_overview.pdf)
> 
> On Tuesday, July 8, 2014 5:09:39 PM UTC-4, vineeth mohan wrote:
> 
> > Hello Gabe ,
> > 
> > Please elaborate on what you mean by custom interval .
> > 
> > Thanks  
> > Vineeth
> > 
> > On Tue, Jul 8, 2014 at 11:25 PM, Gabe Gorelick-Feldman \<  
> > [gabego...@gmail.com](mailto:gabego...@gmail.com)\> wrote:
> > 
> > > Is there any way to use a custom interval with date histograms (either  
> > > facets or aggregations)? For example, something like
> > > 
> > > ```
> > > {
> > > "date_histogram": {
> > > "field": "date",
> > > "interval": "fiscalYear"
> > > }
> > > }
> > > 
> > > ```
> > > 
> > > Obviously, you can always use a regular histogram, but then the client  
> > > would have to manage all the complexities that come with dealing with time.
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > 
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%  
> > > [40googlegroups.com](http://40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%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/b8617abb-ed9e-4fff-95f6-cb81a3def727%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%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/CAGdPd5mNw06nSfLdjDV%2BYK829AR%2Bxk2sKZmerVvjyEbg7HWPjA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mNw06nSfLdjDV%2BYK829AR%2Bxk2sKZmerVvjyEbg7HWPjA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Gabe\_Gorelick\_Feldma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabe_gorelick_feldma/32/1423_2.png) [@Gabe\_Gorelick\_Feldma](https://discuss.elastic.co/u/Gabe_Gorelick_Feldma)
#### Post date: [July 8, 2014, 9:40pm UTC](https://discuss.elastic.co/t/custom-date-histogram-interval/18536/5 "2014-07-08T21:40:05Z")

</div>

That solves the decade or millisecond problem, but wouldn't work for  
something like "MMWR week" or "fiscal year" which are more complex. Here's  
the CDC's definition of MMWR week to illustrate my point:

The first day of any MMWR week is Sunday. MMWR week numbering is sequential

> beginning with 1 and  
> incrementing with each week to a maximum of 52 or 53. MMWR week #1 of an  
> MMWR year is the first week of  
> the year that has at least four days in the calendar year. For example, if  
> January 1 occurs on a Sunday, Monday,  
> Tuesday or Wednesday, the calendar week that includes January 1 would be  
> MMWR week #1. If January 1  
> occurs on a Thursday, Friday, or Saturday, the calendar week that includes  
> January 1 would be the last MMWR  
> week of the previous year (#52 or #53). Because of this rule, December 29,  
> 30, and 31 could potentially fall into  
> MMWR week #1 of the following MMWR year.

On Tuesday, July 8, 2014 5:29:54 PM UTC-4, vineeth mohan wrote:

> Hello Gabe ,
> 
> You can mention the range as 1.5h or 2w and all -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html)
> 
> Hope that might help your cause.
> 
> Thanks  
> Vineeth
> 
> On Wed, Jul 9, 2014 at 2:49 AM, Gabe Gorelick-Feldman \<[gabego...@gmail.com](mailto:gabego...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Sure. According to the docs [1], the available expressions for  
> > date\_histogram interval are year, quarter, month, week, day, hour, minute,  
> > second. But what if you want to rollup by another interval that's not  
> > supported, like decade or millisecond? I was just wondering if there was  
> > maybe a way to write a plugin for such custom intervals.
> > 
> > Specifically, I need a CDC MMWR week [2] interval, which is similar to  
> > ISO week (which I assume is what elasticsearch uses), but not exactly the  
> > same.
> > 
> > [1]  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html)  
> > [2] [http://wwwn.cdc.gov/nndss/document/MMWR\_Week\_overview.pdf](http://wwwn.cdc.gov/nndss/document/MMWR_Week_overview.pdf)
> > 
> > On Tuesday, July 8, 2014 5:09:39 PM UTC-4, vineeth mohan wrote:
> > 
> > > Hello Gabe ,
> > > 
> > > Please elaborate on what you mean by custom interval .
> > > 
> > > Thanks  
> > > Vineeth
> > > 
> > > On Tue, Jul 8, 2014 at 11:25 PM, Gabe Gorelick-Feldman \<  
> > > [gabego...@gmail.com](mailto:gabego...@gmail.com)\> wrote:
> > > 
> > > > Is there any way to use a custom interval with date histograms  
> > > > (either facets or aggregations)? For example, something like
> > > > 
> > > > ```
> > > > {
> > > > "date_histogram": {
> > > > "field": "date",
> > > > "interval": "fiscalYear"
> > > > }
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > Obviously, you can always use a regular histogram, but then the client  
> > > > would have to manage all the complexities that come with dealing with time.
> > > > 
> > > > --  
> > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > 
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%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/9c905198-0926-4cd9-ac43-438c29fa59a6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9c905198-0926-4cd9-ac43-438c29fa59a6%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 8, 2014, 9:53pm UTC](https://discuss.elastic.co/t/custom-date-histogram-interval/18536/6 "2014-07-08T21:53:33Z")

</div>

Hello Gabe ,

Th only thing , I can think of would be to store the fiscal year date as a  
separate field while indexing.  
And then do all manipulation on this date.

Thanks  
Vineeth

On Wed, Jul 9, 2014 at 3:10 AM, Gabe Gorelick-Feldman \<  
[gabegorelick@gmail.com](mailto:gabegorelick@gmail.com)\> wrote:

> That solves the decade or millisecond problem, but wouldn't work for  
> something like "MMWR week" or "fiscal year" which are more complex. Here's  
> the CDC's definition of MMWR week to illustrate my point:
> 
> The first day of any MMWR week is Sunday. MMWR week numbering is
> 
> > sequential beginning with 1 and  
> > incrementing with each week to a maximum of 52 or 53. MMWR week #1 of an  
> > MMWR year is the first week of  
> > the year that has at least four days in the calendar year. For example,  
> > if January 1 occurs on a Sunday, Monday,  
> > Tuesday or Wednesday, the calendar week that includes January 1 would be  
> > MMWR week #1. If January 1  
> > occurs on a Thursday, Friday, or Saturday, the calendar week that  
> > includes January 1 would be the last MMWR  
> > week of the previous year (#52 or #53). Because of this rule, December  
> > 29, 30, and 31 could potentially fall into  
> > MMWR week #1 of the following MMWR year.
> 
> On Tuesday, July 8, 2014 5:29:54 PM UTC-4, vineeth mohan wrote:
> 
> > Hello Gabe ,
> > 
> > You can mention the range as 1.5h or 2w and all -  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > reference/current/search-aggregations-bucket-  
> > datehistogram-aggregation.html
> > 
> > Hope that might help your cause.
> > 
> > Thanks  
> > Vineeth
> > 
> > On Wed, Jul 9, 2014 at 2:49 AM, Gabe Gorelick-Feldman \<  
> > [gabego...@gmail.com](mailto:gabego...@gmail.com)\> wrote:
> > 
> > > Sure. According to the docs [1], the available expressions for  
> > > date\_histogram interval are year, quarter, month, week, day, hour, minute,  
> > > second. But what if you want to rollup by another interval that's not  
> > > supported, like decade or millisecond? I was just wondering if there was  
> > > maybe a way to write a plugin for such custom intervals.
> > > 
> > > Specifically, I need a CDC MMWR week [2] interval, which is similar to  
> > > ISO week (which I assume is what elasticsearch uses), but not exactly the  
> > > same.
> > > 
> > > [1] [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > > reference/current/search-aggregations-bucket-  
> > > datehistogram-aggregation.html  
> > > [2] [http://wwwn.cdc.gov/nndss/document/MMWR\_Week\_overview.pdf](http://wwwn.cdc.gov/nndss/document/MMWR_Week_overview.pdf)
> > > 
> > > On Tuesday, July 8, 2014 5:09:39 PM UTC-4, vineeth mohan wrote:
> > > 
> > > > Hello Gabe ,
> > > > 
> > > > Please elaborate on what you mean by custom interval .
> > > > 
> > > > Thanks  
> > > > Vineeth
> > > > 
> > > > On Tue, Jul 8, 2014 at 11:25 PM, Gabe Gorelick-Feldman \<  
> > > > [gabego...@gmail.com](mailto:gabego...@gmail.com)\> wrote:
> > > > 
> > > > > Is there any way to use a custom interval with date histograms  
> > > > > (either facets or aggregations)? For example, something like
> > > > > 
> > > > > ```
> > > > > {
> > > > > "date_histogram": {
> > > > > "field": "date",
> > > > > "interval": "fiscalYear"
> > > > > }
> > > > > }
> > > > > 
> > > > > ```
> > > > > 
> > > > > Obviously, you can always use a regular histogram, but then the client  
> > > > > would have to manage all the complexities that come with dealing with time.
> > > > > 
> > > > > --  
> > > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > 
> > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%40goo  
> > > > > [glegroups.com](http://glegroups.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%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/9c905198-0926-4cd9-ac43-438c29fa59a6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9c905198-0926-4cd9-ac43-438c29fa59a6%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/9c905198-0926-4cd9-ac43-438c29fa59a6%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9c905198-0926-4cd9-ac43-438c29fa59a6%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/CAGdPd5n8JeYxGZAQ\_SjMdHaUycGm2nSGwJeqKGJGUp%2BTZg2gzA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5n8JeYxGZAQ_SjMdHaUycGm2nSGwJeqKGJGUp%2BTZg2gzA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Gabe\_Gorelick\_Feldma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabe_gorelick_feldma/32/1423_2.png) [@Gabe\_Gorelick\_Feldma](https://discuss.elastic.co/u/Gabe_Gorelick_Feldma)
#### Post date: [July 8, 2014, 9:57pm UTC](https://discuss.elastic.co/t/custom-date-histogram-interval/18536/7 "2014-07-08T21:57:10Z")

</div>

Thanks, I might do that. Just wanted to make sure there wasn't some easy  
way to have an "interval script"

On Tuesday, July 8, 2014 5:53:39 PM UTC-4, vineeth mohan wrote:

> Hello Gabe ,
> 
> Th only thing , I can think of would be to store the fiscal year date as a  
> separate field while indexing.  
> And then do all manipulation on this date.
> 
> Thanks  
> Vineeth
> 
> On Wed, Jul 9, 2014 at 3:10 AM, Gabe Gorelick-Feldman \<[gabego...@gmail.com](mailto:gabego...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > That solves the decade or millisecond problem, but wouldn't work for  
> > something like "MMWR week" or "fiscal year" which are more complex. Here's  
> > the CDC's definition of MMWR week to illustrate my point:
> > 
> > The first day of any MMWR week is Sunday. MMWR week numbering is
> > 
> > > sequential beginning with 1 and  
> > > incrementing with each week to a maximum of 52 or 53. MMWR week #1 of an  
> > > MMWR year is the first week of  
> > > the year that has at least four days in the calendar year. For example,  
> > > if January 1 occurs on a Sunday, Monday,  
> > > Tuesday or Wednesday, the calendar week that includes January 1 would be  
> > > MMWR week #1. If January 1  
> > > occurs on a Thursday, Friday, or Saturday, the calendar week that  
> > > includes January 1 would be the last MMWR  
> > > week of the previous year (#52 or #53). Because of this rule, December  
> > > 29, 30, and 31 could potentially fall into  
> > > MMWR week #1 of the following MMWR year.
> > 
> > On Tuesday, July 8, 2014 5:29:54 PM UTC-4, vineeth mohan wrote:
> > 
> > > Hello Gabe ,
> > > 
> > > You can mention the range as 1.5h or 2w and all -  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > > reference/current/search-aggregations-bucket-  
> > > datehistogram-aggregation.html
> > > 
> > > Hope that might help your cause.
> > > 
> > > Thanks  
> > > Vineeth
> > > 
> > > On Wed, Jul 9, 2014 at 2:49 AM, Gabe Gorelick-Feldman \<  
> > > [gabego...@gmail.com](mailto:gabego...@gmail.com)\> wrote:
> > > 
> > > > Sure. According to the docs [1], the available expressions for  
> > > > date\_histogram interval are year, quarter, month, week, day, hour, minute,  
> > > > second. But what if you want to rollup by another interval that's not  
> > > > supported, like decade or millisecond? I was just wondering if there was  
> > > > maybe a way to write a plugin for such custom intervals.
> > > > 
> > > > Specifically, I need a CDC MMWR week [2] interval, which is similar to  
> > > > ISO week (which I assume is what elasticsearch uses), but not exactly the  
> > > > same.
> > > > 
> > > > [1] [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > > > reference/current/search-aggregations-bucket-  
> > > > datehistogram-aggregation.html  
> > > > [2] [http://wwwn.cdc.gov/nndss/document/MMWR\_Week\_overview.pdf](http://wwwn.cdc.gov/nndss/document/MMWR_Week_overview.pdf)
> > > > 
> > > > On Tuesday, July 8, 2014 5:09:39 PM UTC-4, vineeth mohan wrote:
> > > > 
> > > > > Hello Gabe ,
> > > > > 
> > > > > Please elaborate on what you mean by custom interval .
> > > > > 
> > > > > Thanks  
> > > > > Vineeth
> > > > > 
> > > > > On Tue, Jul 8, 2014 at 11:25 PM, Gabe Gorelick-Feldman \<  
> > > > > [gabego...@gmail.com](mailto:gabego...@gmail.com)\> wrote:
> > > > > 
> > > > > > Is there any way to use a custom interval with date histograms  
> > > > > > (either facets or aggregations)? For example, something like
> > > > > > 
> > > > > > ```
> > > > > > {
> > > > > > "date_histogram": {
> > > > > > "field": "date",
> > > > > > "interval": "fiscalYear"
> > > > > > }
> > > > > > }
> > > > > > 
> > > > > > ```
> > > > > > 
> > > > > > Obviously, you can always use a regular histogram, but then the  
> > > > > > client would have to manage all the complexities that come with dealing  
> > > > > > with time.
> > > > > > 
> > > > > > --  
> > > > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > 
> > > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > > msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%40goo  
> > > > > > [glegroups.com](http://glegroups.com)  
> > > > > > [https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/37ef7076-f68f-49ff-bd48-3d8431a576d1%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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%  
> > > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/b8617abb-ed9e-4fff-95f6-cb81a3def727%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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/9c905198-0926-4cd9-ac43-438c29fa59a6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9c905198-0926-4cd9-ac43-438c29fa59a6%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/9c905198-0926-4cd9-ac43-438c29fa59a6%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9c905198-0926-4cd9-ac43-438c29fa59a6%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/e99adff6-d7d1-40db-a4db-998ba10347ae%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e99adff6-d7d1-40db-a4db-998ba10347ae%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, 1:17am UTC](https://discuss.elastic.co/t/custom-date-histogram-interval/18536/8 "2017-07-06T01:17:13Z")

</div>


