# Minimum and Maximum date in Elasticsearch

**URL:** https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239
**Category:** Elasticsearch
**Created:** [April 5, 2012, 8:59am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239 "2012-04-05T08:59:51Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 5, 2012, 8:59am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/1 "2012-04-05T08:59:51Z")

</div>

Hi,  
Is there any alternative in elasticsearch for the MySqlQuery

SELECT MIN(Date) AS MINDATE, MAX(Date) AS MAXDATE, HOUR(Date) FROM  
TableName;

How can I get the minimum or maximum date in elasticsearch?

Cheers

George

---

<div class="post-metadata">

### Author: ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)
#### Post date: [April 5, 2012, 4:05pm UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/2 "2012-04-05T16:05:36Z")

</div>

On Apr 5, 1:59 am, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:

> How can I get the minimum or maximum date in elasticsearch?

With a statistical facet:

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

---

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 7, 2012, 6:10am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/3 "2012-04-07T06:10:26Z")

</div>

Thank You Eric Jain

Cheers!!

George

On Apr 5, 9:05 pm, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:

> On Apr 5, 1:59 am, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > How can I get the minimum or maximum date in elasticsearch?
> 
> With a statistical facet:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/statis)...

---

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 10, 2012, 7:45am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/4 "2012-04-10T07:45:11Z")

</div>

Hi,  
I tried the statistical facet for getting the minimum and maximum  
date. I got the output as

createddate" : {  
"\_type" : "statistical",  
"count" : 158,  
"total" : 2.10720682311E14,  
"min" : 1.3332708E12,  
"max" : 1.3340484E12,  
"mean" : 1.3336752045E12,  
"sum\_of\_squares" : 2.8103295903276077E26,  
"variance" : 6.30332803714792E16,  
"std\_deviation" : 2.510642952940127E8  
}

How can I get the actual minimum and maximum date from here?

(For example the min or max date may be this format:

"createddate" : "2012-04-10T09:00:00.000Z",)

cheers!

George

On Apr 7, 11:10 am, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:

> Thank You Eric Jain
> 
> Cheers!!
> 
> George
> 
> On Apr 5, 9:05 pm, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:
> 
> > On Apr 5, 1:59 am,GeorgeViju[vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > > How can I get the minimum or maximum date in elasticsearch?
> 
> > With a statistical facet:
> 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/statis)...

---

<div class="post-metadata">

### Author: ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)
#### Post date: [April 10, 2012, 8:40am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/5 "2012-04-10T08:40:31Z")

</div>

On Tue, Apr 10, 2012 at 00:45, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:

> ```
> "min" : 1.3332708E12,
> 
> ```

Looks like you'll need to convert the float to a long to a date yourself...

-\> 2012-04-01T09:00:00.000Z

---

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 10, 2012, 9:41am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/6 "2012-04-10T09:41:36Z")

</div>

Thank you Eric Jain. I converted the min value 1.3332708E12 to  
date returns 2012-04-01 14:30:06, But the actual minimum date is  
2012-04-01 09:00:00,  
and max value 1.3340484E12 to date returns 2012-04-10 14:30:56,  
But the actual maximum date is 2012-04-10 09:00:00. There is a  
difference in time in both date.

Cheers!

George

On Apr 10, 1:40 pm, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:

> On Tue, Apr 10, 2012 at 00:45, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > ```
> > "min" : 1.3332708E12,
> > 
> > ```
> 
> Looks like you'll need to convert the float to a long to a date yourself...
> 
> -\> 2012-04-01T09:00:00.000Z

---

<div class="post-metadata">

### Author: ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)
#### Post date: [April 10, 2012, 9:54am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/7 "2012-04-10T09:54:01Z")

</div>

On Tue, Apr 10, 2012 at 02:41, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:

> Thank you Eric Jain. I converted the min value 1.3332708E12 to  
> date returns 2012-04-01 14:30:06, But the actual minimum date is  
> 2012-04-01 09:00:00,  
> and max value 1.3340484E12 to date returns 2012-04-10 14:30:56,  
> But the actual maximum date is 2012-04-10 09:00:00. There is a  
> difference in time in both date.

Can you show the code you use for the conversion?

new DateTime((long) 1.3332708E12, DateTimeZone.UTC);  
-\> 2012-04-01T09:00:00.000Z

---

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 10, 2012, 10:32am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/8 "2012-04-10T10:32:09Z")

</div>

Thank you very much Eric Jain. I have used Date method instead of  
joda time in the code. Now it is working fine.

Cheers!

George

On Apr 10, 2:54 pm, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:

> On Tue, Apr 10, 2012 at 02:41, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > Thank you Eric Jain. I converted the min value 1.3332708E12 to  
> > date returns 2012-04-01 14:30:06, But the actual minimum date is  
> > 2012-04-01 09:00:00,  
> > and max value 1.3340484E12 to date returns 2012-04-10 14:30:56,  
> > But the actual maximum date is 2012-04-10 09:00:00. There is a  
> > difference in time in both date.
> 
> Can you show the code you use for the conversion?
> 
> new DateTime((long) 1.3332708E12, DateTimeZone.UTC);  
> -\> 2012-04-01T09:00:00.000Z

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [April 11, 2012, 11:33am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/9 "2012-04-11T11:33:50Z")

</div>

Yea, the date returned in this case is milliseconds since the epoch (UTC).

On Tue, Apr 10, 2012 at 1:32 PM, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:

> Thank you very much Eric Jain. I have used Date method instead of  
> joda time in the code. Now it is working fine.
> 
> Cheers!
> 
> George
> 
> On Apr 10, 2:54 pm, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:
> 
> > On Tue, Apr 10, 2012 at 02:41, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > 
> > > Thank you Eric Jain. I converted the min value 1.3332708E12 to  
> > > date returns 2012-04-01 14:30:06, But the actual minimum date is  
> > > 2012-04-01 09:00:00,  
> > > and max value 1.3340484E12 to date returns 2012-04-10 14:30:56,  
> > > But the actual maximum date is 2012-04-10 09:00:00. There is a  
> > > difference in time in both date.
> > 
> > Can you show the code you use for the conversion?
> > 
> > new DateTime((long) 1.3332708E12, DateTimeZone.UTC);  
> > -\> 2012-04-01T09:00:00.000Z

---

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 11, 2012, 1:51pm UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/10 "2012-04-11T13:51:42Z")

</div>

Thank You Shay.

I got the minimum and maximum date from the statistical facet and the  
output is

"createddatecount" : {  
"\_type" : "statistical",  
"count" : 17,  
"total" : 2.2680306797E13,  
"min" : 1.3341348E12,  
"max" : 1.334144297E12,  
"mean" : 1.3341356939411765E12,  
"sum\_of\_squares" : 3.025860684752347E25,  
"variance" : 6.417439075629177E12,  
"std\_deviation" : 2533266.483343033  
},

By using the dateHistogramFacet I get the post count of each date

```
"createddaterange" : {
  "_type" : "date_histogram",
  "entries" : [ {
    "time" : 1334134800000,
    "count" : 15
  }, {
    "time" : 1334138400000,
    "count" : 1
  }, {
    "time" : 1334142000000,
    "count" : 1
  } ]
}

```

How can I get the minimum and maximum date and the count of each  
date in a single Facet?

Cheers!!

George

On Apr 11, 4:33 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Yea, the date returned in this case is milliseconds since the epoch (UTC).
> 
> On Tue, Apr 10, 2012 at 1:32 PM, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > Thank you very much Eric Jain. I have used Date method instead of  
> > joda time in the code. Now it is working fine.
> 
> > Cheers!
> 
> > George
> 
> > On Apr 10, 2:54 pm, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:
> > 
> > > On Tue, Apr 10, 2012 at 02:41, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > > 
> > > > Thank you Eric Jain. I converted the min value 1.3332708E12 to  
> > > > date returns 2012-04-01 14:30:06, But the actual minimum date is  
> > > > 2012-04-01 09:00:00,  
> > > > and max value 1.3340484E12 to date returns 2012-04-10 14:30:56,  
> > > > But the actual maximum date is 2012-04-10 09:00:00. There is a  
> > > > difference in time in both date.
> 
> > > Can you show the code you use for the conversion?
> 
> > > new DateTime((long) 1.3332708E12, DateTimeZone.UTC);  
> > > -\> 2012-04-01T09:00:00.000Z

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [April 11, 2012, 6:46pm UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/11 "2012-04-11T18:46:04Z")

</div>

You mean each date in the date histogram? You need to add a value field  
(can be the same date field), in which case, stats will be computed on it.

On Wed, Apr 11, 2012 at 4:51 PM, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:

> Thank You Shay.
> 
> I got the minimum and maximum date from the statistical facet and the  
> output is
> 
> "createddatecount" : {  
> "\_type" : "statistical",  
> "count" : 17,  
> "total" : 2.2680306797E13,  
> "min" : 1.3341348E12,  
> "max" : 1.334144297E12,  
> "mean" : 1.3341356939411765E12,  
> "sum\_of\_squares" : 3.025860684752347E25,  
> "variance" : 6.417439075629177E12,  
> "std\_deviation" : 2533266.483343033  
> },
> 
> By using the dateHistogramFacet I get the post count of each date
> 
> "createddaterange" : {  
> "\_type" : "date\_histogram",  
> "entries" : [ {  
> "time" : 1334134800000,  
> "count" : 15  
> }, {  
> "time" : 1334138400000,  
> "count" : 1  
> }, {  
> "time" : 1334142000000,  
> "count" : 1  
> } ]  
> }
> 
> How can I get the minimum and maximum date and the count of each  
> date in a single Facet?
> 
> Cheers!!
> 
> George
> 
> On Apr 11, 4:33 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Yea, the date returned in this case is milliseconds since the epoch  
> > (UTC).
> > 
> > On Tue, Apr 10, 2012 at 1:32 PM, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com)  
> > wrote:
> > 
> > > Thank you very much Eric Jain. I have used Date method instead of  
> > > joda time in the code. Now it is working fine.
> > 
> > > Cheers!
> > 
> > > George
> > 
> > > On Apr 10, 2:54 pm, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:
> > > 
> > > > On Tue, Apr 10, 2012 at 02:41, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com)  
> > > > wrote:
> > > > 
> > > > > Thank you Eric Jain. I converted the min value 1.3332708E12 to  
> > > > > date returns 2012-04-01 14:30:06, But the actual minimum date is  
> > > > > 2012-04-01 09:00:00,  
> > > > > and max value 1.3340484E12 to date returns 2012-04-10 14:30:56,  
> > > > > But the actual maximum date is 2012-04-10 09:00:00. There is a  
> > > > > difference in time in both date.
> > 
> > > > Can you show the code you use for the conversion?
> > 
> > > > new DateTime((long) 1.3332708E12, DateTimeZone.UTC);  
> > > > -\> 2012-04-01T09:00:00.000Z

---

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 12, 2012, 6:26am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/12 "2012-04-12T06:26:45Z")

</div>

Thank you Shay.

Yes, for each date or time in date Histogram I need the statistical  
data of min and max values.

" You need to add a value field  
(can be the same date field), in which case, stats will be computed on  
it."

Could you please clarify this?

Thanks in advance!

Cheers!

George

On Apr 11, 11:46 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> You mean each date in the date histogram? You need to add a value field  
> (can be the same date field), in which case, stats will be computed on it.
> 
> On Wed, Apr 11, 2012 at 4:51 PM, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > Thank You Shay.
> 
> > I got the minimum and maximum date from the statistical facet and the  
> > output is
> 
> > "createddatecount" : {  
> > "\_type" : "statistical",  
> > "count" : 17,  
> > "total" : 2.2680306797E13,  
> > "min" : 1.3341348E12,  
> > "max" : 1.334144297E12,  
> > "mean" : 1.3341356939411765E12,  
> > "sum\_of\_squares" : 3.025860684752347E25,  
> > "variance" : 6.417439075629177E12,  
> > "std\_deviation" : 2533266.483343033  
> > },
> 
> > By using the dateHistogramFacet I get the post count of each date
> 
> > "createddaterange" : {  
> > "\_type" : "date\_histogram",  
> > "entries" : [ {  
> > "time" : 1334134800000,  
> > "count" : 15  
> > }, {  
> > "time" : 1334138400000,  
> > "count" : 1  
> > }, {  
> > "time" : 1334142000000,  
> > "count" : 1  
> > } ]  
> > }
> 
> > How can I get the minimum and maximum date and the count of each  
> > date in a single Facet?
> 
> > Cheers!!
> 
> > George
> 
> > On Apr 11, 4:33 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > Yea, the date returned in this case is milliseconds since the epoch  
> > > (UTC).
> 
> > > On Tue, Apr 10, 2012 at 1:32 PM, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com)  
> > > wrote:
> > > 
> > > > Thank you very much Eric Jain. I have used Date method instead of  
> > > > joda time in the code. Now it is working fine.
> 
> > > > Cheers!
> 
> > > > George
> 
> > > > On Apr 10, 2:54 pm, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:
> > > > 
> > > > > On Tue, Apr 10, 2012 at 02:41, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com)  
> > > > > wrote:
> > > > > 
> > > > > > Thank you Eric Jain. I converted the min value 1.3332708E12 to  
> > > > > > date returns 2012-04-01 14:30:06, But the actual minimum date is  
> > > > > > 2012-04-01 09:00:00,  
> > > > > > and max value 1.3340484E12 to date returns 2012-04-10 14:30:56,  
> > > > > > But the actual maximum date is 2012-04-10 09:00:00. There is a  
> > > > > > difference in time in both date.
> 
> > > > > Can you show the code you use for the conversion?
> 
> > > > > new DateTime((long) 1.3332708E12, DateTimeZone.UTC);  
> > > > > -\> 2012-04-01T09:00:00.000Z

---

<div class="post-metadata">

### Author: ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)
#### Post date: [April 12, 2012, 6:43am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/13 "2012-04-12T06:43:21Z")

</div>

On Wed, Apr 11, 2012 at 23:26, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:

> " You need to add a value field  
> (can be the same date field), in which case, stats will be computed on  
> it."
> 
> Could you please clarify this?

See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/date-histogram-facet.html),  
"Value Field".

---

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 12, 2012, 7:39am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/14 "2012-04-12T07:39:45Z")

</div>

ok. Thank you Eric Jain

Cheers!

George

On Apr 12, 11:43 am, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:

> On Wed, Apr 11, 2012 at 23:26, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > " You need to add a value field  
> > (can be the same date field), in which case, stats will be computed on  
> > it."
> 
> > Could you please clarify this?
> 
> Seehttp://www.elasticsearch.org/guide/reference/api/search/facets/date-h...,  
> "Value Field".

---

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 12, 2012, 12:35pm UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/15 "2012-04-12T12:35:27Z")

</div>

Hi,  
I can get the data for year, month, week, day, hour, minute Date  
Histogram facet. Is there any method to get the quarter(3 months)  
period data in date Histogram Facet?

Cheers!!

George

On Apr 12, 12:39 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:

> ok. Thank you Eric Jain
> 
> Cheers!
> 
> George
> 
> On Apr 12, 11:43 am, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:
> 
> > On Wed, Apr 11, 2012 at 23:26, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > 
> > > " You need to add a value field  
> > > (can be the same date field), in which case, stats will be computed on  
> > > it."
> 
> > > Could you please clarify this?
> 
> > Seehttp://www.elasticsearch.org/guide/reference/api/search/facets/date-h...,  
> > "Value Field".

---

<div class="post-metadata">

### Author: ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)
#### Post date: [April 12, 2012, 6:26pm UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/16 "2012-04-12T18:26:16Z")

</div>

On Thu, Apr 12, 2012 at 05:35, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:

> I can get the data for year, month, week, day, hour, minute Date  
> Histogram facet. Is there any method to get the quarter(3 months)  
> period data in date Histogram Facet?

Get the months and add them up?

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [April 13, 2012, 12:29pm UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/17 "2012-04-13T12:29:30Z")

</div>

Getting the months and adding them up is your best option, there isn't a "3  
months" option.

On Thu, Apr 12, 2012 at 9:26 PM, Eric Jain [eric.jain@gmail.com](mailto:eric.jain@gmail.com) wrote:

> On Thu, Apr 12, 2012 at 05:35, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:
> 
> > I can get the data for year, month, week, day, hour, minute Date  
> > Histogram facet. Is there any method to get the quarter(3 months)  
> > period data in date Histogram Facet?
> 
> Get the months and add them up?

---

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 16, 2012, 3:56am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/18 "2012-04-16T03:56:00Z")

</div>

Thank You.. I tried the Date Histogram Facet for getting the weeks.  
Here I am getting the Week starting from Monday to Sunday as one Week.  
Is there any method to get the Week that should start from Sunday to  
Saturday as one Week.

For Example, If I am taking the date from April 1 to April 13, The  
Week count Should be 2, but I am getting 3 weeks because It is taking  
the week start from Monday to Sunday.

"daterange" : {  
"\_type" : "date\_histogram",  
"entries" : [ {  
"time" : 1332720000000,  
"count" : 15,  
"min" : 1.3332708E12,  
"max" : 1.3332708E12,  
"total" : 1.9999062E13,  
"total\_count" : 15,  
"mean" : 1.3332708E12  
}, {  
"time" : 1333324800000,  
"count" : 105,  
"min" : 1.3333572E12,  
"max" : 1.3338756E12,  
"total" : 1.40029722E14,  
"total\_count" : 105,  
"mean" : 1.3336164E12  
}, {  
"time" : 1333929600000,  
"count" : 85,  
"min" : 1.333962E12,  
"max" : 1.3343076E12,  
"total" : 1.13400137108E14,  
"total\_count" : 85,  
"mean" : 1.3341192600941177E12  
} ]  
}

Is there any method to get the Week that should start from Sunday to  
Saturday as one Week?

Cheers!

George

On Apr 13, 5:29 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Getting the months and adding them up is your best option, there isn't a "3  
> months" option.
> 
> On Thu, Apr 12, 2012 at 9:26 PM, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:
> 
> > On Thu, Apr 12, 2012 at 05:35, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > 
> > > I can get the data for year, month, week, day, hour, minute Date  
> > > Histogram facet. Is there any method to get the quarter(3 months)  
> > > period data in date Histogram Facet?
> 
> > Get the months and add them up?

---

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 17, 2012, 7:30am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/19 "2012-04-17T07:30:17Z")

</div>

Hi,  
How to use TimeZoneRounding.Builder method postOffset(113232)  
here to make it start from Sunday to Saturday as referred in

> <https://github.com/elastic/elasticsearch/issues/1599>
>
> Allow to define a \`pre\_offset\` and \`post\_offset\` for offsets applying pre roundi…ng and post rounding. The values are time values with a possible \`-\` sign.
> 
> For example, to offset a \`week\` rounding to start on Sunday instead of Monday, one can pass \`pre\_offset\` of \`-1d\` to decrease a day \_before\_ doing the week (monday based) rounding, and then have \`post\_offset\` set to \`-1d\` to actually set the return value to be Sunday, and not Monday.

Cheers!

George

On Apr 16, 8:56 am, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:

> Thank You.. I tried the Date Histogram Facet for getting the weeks.  
> Here I am getting the Week starting from Monday to Sunday as one Week.  
> Is there any method to get the Week that should start from Sunday to  
> Saturday as one Week.
> 
> For Example, If I am taking the date from April 1 to April 13, The  
> Week count Should be 2, but I am getting 3 weeks because It is taking  
> the week start from Monday to Sunday.
> 
> "daterange" : {  
> "\_type" : "date\_histogram",  
> "entries" : [ {  
> "time" : 1332720000000,  
> "count" : 15,  
> "min" : 1.3332708E12,  
> "max" : 1.3332708E12,  
> "total" : 1.9999062E13,  
> "total\_count" : 15,  
> "mean" : 1.3332708E12  
> }, {  
> "time" : 1333324800000,  
> "count" : 105,  
> "min" : 1.3333572E12,  
> "max" : 1.3338756E12,  
> "total" : 1.40029722E14,  
> "total\_count" : 105,  
> "mean" : 1.3336164E12  
> }, {  
> "time" : 1333929600000,  
> "count" : 85,  
> "min" : 1.333962E12,  
> "max" : 1.3343076E12,  
> "total" : 1.13400137108E14,  
> "total\_count" : 85,  
> "mean" : 1.3341192600941177E12  
> } ]  
> }
> 
> Is there any method to get the Week that should start from Sunday to  
> Saturday as one Week?
> 
> Cheers!
> 
> George
> 
> On Apr 13, 5:29 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Getting the months and adding them up is your best option, there isn't a "3  
> > months" option.
> 
> > On Thu, Apr 12, 2012 at 9:26 PM, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:
> > 
> > > On Thu, Apr 12, 2012 at 05:35,GeorgeViju[vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > > 
> > > > I can get the data for year, month, week, day, hour, minute Date  
> > > > Histogram facet. Is there any method to get the quarter(3 months)  
> > > > period data in date Histogram Facet?
> 
> > > Get the months and add them up?

---

<div class="post-metadata">

### Author: ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)
#### Post date: [April 18, 2012, 3:53am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/20 "2012-04-18T03:53:40Z")

</div>

Hi,  
Is there any method to make the week to start from Sunday and  
ends at Saturday? How to use postOffset() method with DateHistogram  
Facet?

Cheers!

George

On Apr 17, 12:30 pm, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:

> Hi,  
> How to use TimeZoneRounding.Builder method postOffset(113232)  
> here to make it start from Sunday to Saturday as referred in
> 
> [Date Histogram Facet: Add `pre_offset` and `post_offset` options · Issue #1599 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1599)
> 
> Cheers!
> 
> George
> 
> On Apr 16, 8:56 am, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > Thank You.. I tried the Date Histogram Facet for getting the weeks.  
> > Here I am getting the Week starting from Monday to Sunday as one Week.  
> > Is there any method to get the Week that should start from Sunday to  
> > Saturday as one Week.
> 
> > For Example, If I am taking the date from April 1 to April 13, The  
> > Week count Should be 2, but I am getting 3 weeks because It is taking  
> > the week start from Monday to Sunday.
> 
> > "daterange" : {  
> > "\_type" : "date\_histogram",  
> > "entries" : [ {  
> > "time" : 1332720000000,  
> > "count" : 15,  
> > "min" : 1.3332708E12,  
> > "max" : 1.3332708E12,  
> > "total" : 1.9999062E13,  
> > "total\_count" : 15,  
> > "mean" : 1.3332708E12  
> > }, {  
> > "time" : 1333324800000,  
> > "count" : 105,  
> > "min" : 1.3333572E12,  
> > "max" : 1.3338756E12,  
> > "total" : 1.40029722E14,  
> > "total\_count" : 105,  
> > "mean" : 1.3336164E12  
> > }, {  
> > "time" : 1333929600000,  
> > "count" : 85,  
> > "min" : 1.333962E12,  
> > "max" : 1.3343076E12,  
> > "total" : 1.13400137108E14,  
> > "total\_count" : 85,  
> > "mean" : 1.3341192600941177E12  
> > } ]  
> > }
> 
> > Is there any method to get the Week that should start from Sunday to  
> > Saturday as one Week?
> 
> > Cheers!
> 
> > George
> 
> > On Apr 13, 5:29 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > > Getting the months and adding them up is your best option, there isn't a "3  
> > > months" option.
> 
> > > On Thu, Apr 12, 2012 at 9:26 PM, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:
> > > 
> > > > On Thu, Apr 12, 2012 at 05:35,GeorgeViju[vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > > > 
> > > > > I can get the data for year, month, week, day, hour, minute Date  
> > > > > Histogram facet. Is there any method to get the quarter(3 months)  
> > > > > period data in date Histogram Facet?
> 
> > > > Get the months and add them up?

[Next page](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239.md?page=2)
