# Time Facet

**URL:** <https://discuss.elastic.co/t/time-facet/6468>\
**Category:** Elasticsearch\
**Created:** [January 23, 2012, 3:33pm UTC](https://discuss.elastic.co/t/time-facet/6468 "2012-01-23T15:33:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ridvan\_Gyundogan](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Ridvan\_Gyundogan](https://discuss.elastic.co/u/Ridvan_Gyundogan)\
**Post date:** [January 23, 2012, 3:33pm UTC](https://discuss.elastic.co/t/time-facet/6468/1 "2012-01-23T15:33:16Z")

</div>

Hi, does anyone know how to make a facet only on the time part of a  
datetime field?  
I was thinking to duplicate the datetime field with only the time  
information filled.

Do you know better solution for this?

---

<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:** [January 23, 2012, 6:36pm UTC](https://discuss.elastic.co/t/time-facet/6468/2 "2012-01-23T18:36:43Z")

</div>

What kind of facet are you after? The date histogram allows to configure  
the interval is will work on.

On Mon, Jan 23, 2012 at 5:33 PM, Ridvan Gyundogan [ridvansg@gmail.com](mailto:ridvansg@gmail.com)wrote:

> Hi, does anyone know how to make a facet only on the time part of a  
> datetime field?  
> I was thinking to duplicate the datetime field with only the time  
> information filled.
> 
> Do you know better solution for this?

---

<div class="post-metadata">

**Author:** ![Mark\_Waddle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_waddle/32/2608_2.png) [@Mark\_Waddle](https://discuss.elastic.co/u/Mark_Waddle)\
**Post date:** [January 24, 2012, 3:26am UTC](https://discuss.elastic.co/t/time-facet/6468/3 "2012-01-24T03:26:56Z")

</div>

Hi Ridvan,

I think your proposed solution is the right one. Use the same date for all  
of them, just specify a different time. In your rendering you can ignore  
the date.

Mark

---

<div class="post-metadata">

**Author:** ![Ridvan\_Gyundogan](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Ridvan\_Gyundogan](https://discuss.elastic.co/u/Ridvan_Gyundogan)\
**Post date:** [January 24, 2012, 7:42am UTC](https://discuss.elastic.co/t/time-facet/6468/4 "2012-01-24T07:42:18Z")

</div>

Hi Shay,  
my case is the following:  
I have Purchases which are created on a certain date and time - the  
field is Purchase.creationDate.

Now I want to know for the last year how many of the purchases have  
been made in the hours 0-8, 8-16, 16-24, no matter the date.  
This is bit different than the date histogram facet which allows me to  
count the purchases for example Jan 1 - March 1, June 1 ....

I can still use the date histogram facet if I create a new field  
Purchase.creationTime which is of type datetime but the year = 0 ,  
month = 0 and day = 1 and the time is the same as in  
Purchase.creationDate,  
I was wondering is there other solution to this?

On Jan 23, 8:36 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> What kind of facet are you after? The date histogram allows to configure  
> the interval is will work on.
> 
> On Mon, Jan 23, 2012 at 5:33 PM, Ridvan Gyundogan [ridva...@gmail.com](mailto:ridva...@gmail.com)wrote:
> 
> > Hi, does anyone know how to make a facet only on the time part of a  
> > datetime field?  
> > I was thinking to duplicate the datetime field with only the time  
> > information filled.
> 
> > Do you know better solution for this?

---

<div class="post-metadata">

**Author:** ![Ridvan\_Gyundogan](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Ridvan\_Gyundogan](https://discuss.elastic.co/u/Ridvan_Gyundogan)\
**Post date:** [January 24, 2012, 7:45am UTC](https://discuss.elastic.co/t/time-facet/6468/5 "2012-01-24T07:45:13Z")

</div>

Thanks Mark

On Jan 24, 5:26 am, Mark Waddle [m...@markwaddle.com](mailto:m...@markwaddle.com) wrote:

> Hi Ridvan,
> 
> I think your proposed solution is the right one. Use the same date for all  
> of them, just specify a different time. In your rendering you can ignore  
> the date.
> 
> Mark

---

<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:** [January 24, 2012, 2:40pm UTC](https://discuss.elastic.co/t/time-facet/6468/6 "2012-01-24T14:40:26Z")

</div>

You have several options:

1. Still use the creationDate, and use a histogram facet, with a key script  
that does: doc.createDate.data.hourOfDay to get the hour. Note, you will  
need to provide a value\_script in this case as well, you can just use a  
script of "1" that simply returns 1 if you don't need anything fancy there.

2. The previous option comes with the overhead of running a script. If you  
don't want it, index an hour field, and use histogram on that.

3. Use your purposed solution, basically having creationTime field that has  
the same day.

On Tue, Jan 24, 2012 at 9:42 AM, Ridvan Gyundogan [ridvansg@gmail.com](mailto:ridvansg@gmail.com)wrote:

> Hi Shay,  
> my case is the following:  
> I have Purchases which are created on a certain date and time - the  
> field is Purchase.creationDate.
> 
> Now I want to know for the last year how many of the purchases have  
> been made in the hours 0-8, 8-16, 16-24, no matter the date.  
> This is bit different than the date histogram facet which allows me to  
> count the purchases for example Jan 1 - March 1, June 1 ....
> 
> I can still use the date histogram facet if I create a new field  
> Purchase.creationTime which is of type datetime but the year = 0 ,  
> month = 0 and day = 1 and the time is the same as in  
> Purchase.creationDate,  
> I was wondering is there other solution to this?
> 
> On Jan 23, 8:36 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > What kind of facet are you after? The date histogram allows to configure  
> > the interval is will work on.
> > 
> > On Mon, Jan 23, 2012 at 5:33 PM, Ridvan Gyundogan \<[ridva...@gmail.com](mailto:ridva...@gmail.com)  
> > wrote:
> > 
> > > Hi, does anyone know how to make a facet only on the time part of a  
> > > datetime field?  
> > > I was thinking to duplicate the datetime field with only the time  
> > > information filled.
> > 
> > > Do you know better solution for this?

---

<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:41am UTC](https://discuss.elastic.co/t/time-facet/6468/7 "2017-07-06T03:41:40Z")

</div>

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


