# 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:** 5\
**Page:** 2

<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 18, 2012, 4:57am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/21 "2012-04-18T04:57:37Z")

</div>

On Tue, Apr 17, 2012 at 20:53, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:

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

How about like so?

DateHistogramFacetBuilder facet = ...  
TimeValue oneDayEarlier = TimeValue.timeValueHours(-24);  
facet.preOffset(oneDayEarlier).postOffset(oneDayEarlier);

---

<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, 6:16am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/22 "2012-04-18T06:16:36Z")

</div>

Thank you Eric Jain!

I tried using the code for the date April 1(Sunday) to 13(Friday)  
but again I am getting 3 week as count

"createddaterange" : {  
"\_type" : "date\_histogram",  
"entries" : [ {  
"time" : 1332633600000,  
"count" : 30,  
"min" : 1.3332708E12,  
"max" : 1.3333572E12,  
"total" : 3.999942E13,  
"total\_count" : 30,  
"mean" : 1.333314E12  
}, {  
"time" : 1333238400000,  
"count" : 113,  
"min" : 1.3334436E12,  
"max" : 1.333967978E12,  
"total" : 1.50710536311E14,  
"total\_count" : 113,  
"mean" : 1.3337215602743362E12  
}, {  
"time" : 1333843200000,  
"count" : 62,  
"min" : 1.3340484E12,  
"max" : 1.3343076E12,  
"total" : 8.2718964797E13,  
"total\_count" : 62,  
"mean" : 1.334176851564516E12  
} ]  
}

The Facet is

"createddaterange" : {  
"date\_histogram" : {  
"key\_field" : "createddate",  
"value\_field" : "createddate",  
"interval" : "week",  
"pre\_offset" : -86400000,  
"post\_offset" : -86400000  
}  
}

Cheers!

George

On Apr 18, 9:57 am, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:

> On Tue, Apr 17, 2012 at 20:53, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > ```
> > Is there any method to make the week to start from Sunday and
> > 
> > ```
> > 
> > ends at Saturday? How to use postOffset() method with DateHistogram  
> > Facet?
> 
> How about like so?
> 
> DateHistogramFacetBuilder facet = ...  
> TimeValue oneDayEarlier = TimeValue.timeValueHours(-24);  
> facet.preOffset(oneDayEarlier).postOffset(oneDayEarlier);

---

<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 19, 2012, 2:33pm UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/23 "2012-04-19T14:33:47Z")

</div>

Settings the offsets should work, what do you mean by 3 weeks?

On Wed, Apr 18, 2012 at 9:16 AM, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:

> Thank you Eric Jain!
> 
> I tried using the code for the date April 1(Sunday) to 13(Friday)  
> but again I am getting 3 week as count
> 
> "createddaterange" : {  
> "\_type" : "date\_histogram",  
> "entries" : [ {  
> "time" : 1332633600000,  
> "count" : 30,  
> "min" : 1.3332708E12,  
> "max" : 1.3333572E12,  
> "total" : 3.999942E13,  
> "total\_count" : 30,  
> "mean" : 1.333314E12  
> }, {  
> "time" : 1333238400000,  
> "count" : 113,  
> "min" : 1.3334436E12,  
> "max" : 1.333967978E12,  
> "total" : 1.50710536311E14,  
> "total\_count" : 113,  
> "mean" : 1.3337215602743362E12  
> }, {  
> "time" : 1333843200000,  
> "count" : 62,  
> "min" : 1.3340484E12,  
> "max" : 1.3343076E12,  
> "total" : 8.2718964797E13,  
> "total\_count" : 62,  
> "mean" : 1.334176851564516E12  
> } ]  
> }
> 
> The Facet is
> 
> "createddaterange" : {  
> "date\_histogram" : {  
> "key\_field" : "createddate",  
> "value\_field" : "createddate",  
> "interval" : "week",  
> "pre\_offset" : -86400000,  
> "post\_offset" : -86400000  
> }  
> }
> 
> Cheers!
> 
> George
> 
> On Apr 18, 9:57 am, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:
> 
> > On Tue, Apr 17, 2012 at 20:53, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > 
> > > ```
> > > Is there any method to make the week to start from Sunday and
> > > 
> > > ```
> > > 
> > > ends at Saturday? How to use postOffset() method with DateHistogram  
> > > Facet?
> > 
> > How about like so?
> > 
> > DateHistogramFacetBuilder facet = ...  
> > TimeValue oneDayEarlier = TimeValue.timeValueHours(-24);  
> > facet.preOffset(oneDayEarlier).postOffset(oneDayEarlier);

---

<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 20, 2012, 3:52am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/24 "2012-04-20T03:52:21Z")

</div>

It means

April 1(Sunday) -- April 7(Saturday) 1 Week

April 8(Sunday) -- April 13(Friday) `1 week

This is the actual count of week here..But it is taking as

3 weeks and showing 3 min max values and 3 counts for 3 weeks

Cheers!

George

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

> Settings the offsets should work, what do you mean by 3 weeks?
> 
> On Wed, Apr 18, 2012 at 9:16 AM, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > Thank you Eric Jain!
> 
> > I tried using the code for the date April 1(Sunday) to 13(Friday)  
> > but again I am getting 3 week as count
> 
> > "createddaterange" : {  
> > "\_type" : "date\_histogram",  
> > "entries" : [ {  
> > "time" : 1332633600000,  
> > "count" : 30,  
> > "min" : 1.3332708E12,  
> > "max" : 1.3333572E12,  
> > "total" : 3.999942E13,  
> > "total\_count" : 30,  
> > "mean" : 1.333314E12  
> > }, {  
> > "time" : 1333238400000,  
> > "count" : 113,  
> > "min" : 1.3334436E12,  
> > "max" : 1.333967978E12,  
> > "total" : 1.50710536311E14,  
> > "total\_count" : 113,  
> > "mean" : 1.3337215602743362E12  
> > }, {  
> > "time" : 1333843200000,  
> > "count" : 62,  
> > "min" : 1.3340484E12,  
> > "max" : 1.3343076E12,  
> > "total" : 8.2718964797E13,  
> > "total\_count" : 62,  
> > "mean" : 1.334176851564516E12  
> > } ]  
> > }
> 
> > The Facet is
> 
> > "createddaterange" : {  
> > "date\_histogram" : {  
> > "key\_field" : "createddate",  
> > "value\_field" : "createddate",  
> > "interval" : "week",  
> > "pre\_offset" : -86400000,  
> > "post\_offset" : -86400000  
> > }  
> > }
> 
> > Cheers!
> 
> > George
> 
> > On Apr 18, 9:57 am, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:
> > 
> > > On Tue, Apr 17, 2012 at 20:53, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> > > 
> > > > ```
> > > > Is there any method to make the week to start from Sunday and
> > > > 
> > > > ```
> > > > 
> > > > ends at Saturday? How to use postOffset() method with DateHistogram  
> > > > Facet?
> 
> > > How about like so?
> 
> > > DateHistogramFacetBuilder facet = ...  
> > > TimeValue oneDayEarlier = TimeValue.timeValueHours(-24);  
> > > facet.preOffset(oneDayEarlier).postOffset(oneDayEarlier);

---

<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, 3:31am UTC](https://discuss.elastic.co/t/minimum-and-maximum-date-in-elasticsearch/7239/25 "2017-07-06T03:31:44Z")

</div>

Closed on July 6, 2017, 3:31am UTC



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