# TermStatsFacet - precalculated?

**URL:** <https://discuss.elastic.co/t/termstatsfacet-precalculated/5939>\
**Category:** Elasticsearch\
**Created:** [November 22, 2011, 1:17pm UTC](https://discuss.elastic.co/t/termstatsfacet-precalculated/5939 "2011-11-22T13:17:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Sick](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Michael\_Sick](https://discuss.elastic.co/u/Michael_Sick)\
**Post date:** [November 22, 2011, 1:17pm UTC](https://discuss.elastic.co/t/termstatsfacet-precalculated/5939/1 "2011-11-22T13:17:08Z")

</div>

I'm just starting to use the TermStatsFacet package and I was curious to  
know if all of the stats (min/max/mean/...) are calculated when a  
TermsStatsFacet response is prepared. If so, isn't this a bit of extra work  
when a consumer will rarely want all of the stats and most often want one  
or two?

Probably not a big concern if we stick with the small set of stats offered  
but if the number of stats grows, it seems like it would be an issue (vs.  
dealing with it as we deal with fields and specifying on the request what  
we want in the response). Guess the same questions apply to the base Stats  
facets as well.

Today, just curious if my understanding of how this works is correct as it  
appears to work well for my current use case. Thanks!

--Mike

---

<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:** [November 22, 2011, 1:54pm UTC](https://discuss.elastic.co/t/termstatsfacet-precalculated/5939/2 "2011-11-22T13:54:46Z")

</div>

The idea with these type of concern is to add flags, that  
enable/disable computation of expensive aspects of the facet.

On Tue, Nov 22, 2011 at 3:17 PM, Michael Sick \<  
[michael.sick@serenesoftware.com](mailto:michael.sick@serenesoftware.com)\> wrote:

> I'm just starting to use the TermStatsFacet package and I was curious to  
> know if all of the stats (min/max/mean/...) are calculated when a  
> TermsStatsFacet response is prepared. If so, isn't this a bit of extra work  
> when a consumer will rarely want all of the stats and most often want one  
> or two?
> 
> Probably not a big concern if we stick with the small set of stats offered  
> but if the number of stats grows, it seems like it would be an issue (vs.  
> dealing with it as we deal with fields and specifying on the request what  
> we want in the response). Guess the same questions apply to the base Stats  
> facets as well.
> 
> Today, just curious if my understanding of how this works is correct as it  
> appears to work well for my current use case. Thanks!
> 
> --Mike

---

<div class="post-metadata">

**Author:** ![Michael\_Sick](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Michael\_Sick](https://discuss.elastic.co/u/Michael_Sick)\
**Post date:** [November 22, 2011, 2:37pm UTC](https://discuss.elastic.co/t/termstatsfacet-precalculated/5939/3 "2011-11-22T14:37:16Z")

</div>

Thanks! That would work just fine (hopefully with an easy button to turn  
them all off and enable a few). If it's ok to pile on a question, I know we  
can do custom scripts to calculate a statistic but was curious if there was  
a good way to define/register a custom stat on the server side.

On Tue, Nov 22, 2011 at 8:54 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> The idea with these type of concern is to add flags, that  
> enable/disable computation of expensive aspects of the facet.
> 
> On Tue, Nov 22, 2011 at 3:17 PM, Michael Sick \<  
> [michael.sick@serenesoftware.com](mailto:michael.sick@serenesoftware.com)\> wrote:
> 
> > I'm just starting to use the TermStatsFacet package and I was curious to  
> > know if all of the stats (min/max/mean/...) are calculated when a  
> > TermsStatsFacet response is prepared. If so, isn't this a bit of extra work  
> > when a consumer will rarely want all of the stats and most often want one  
> > or two?
> > 
> > Probably not a big concern if we stick with the small set of stats  
> > offered but if the number of stats grows, it seems like it would be an  
> > issue (vs. dealing with it as we deal with fields and specifying on the  
> > request what we want in the response). Guess the same questions apply to  
> > the base Stats facets as well.
> > 
> > Today, just curious if my understanding of how this works is correct as  
> > it appears to work well for my current use case. Thanks!
> > 
> > --Mike

---

<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:** [November 22, 2011, 3:43pm UTC](https://discuss.elastic.co/t/termstatsfacet-precalculated/5939/4 "2011-11-22T15:43:31Z")

</div>

What do you mean by custom stat? You can plug in your own script to provide  
a value (and then you get total, min, max for it). That script can do  
whatever you want. If you want completely custom code, you can plug in your  
own facet implementation, but its not that simple.

On Tue, Nov 22, 2011 at 4:37 PM, Michael Sick \<  
[michael.sick@serenesoftware.com](mailto:michael.sick@serenesoftware.com)\> wrote:

> Thanks! That would work just fine (hopefully with an easy button to turn  
> them all off and enable a few). If it's ok to pile on a question, I know we  
> can do custom scripts to calculate a statistic but was curious if there was  
> a good way to define/register a custom stat on the server side.
> 
> On Tue, Nov 22, 2011 at 8:54 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > The idea with these type of concern is to add flags, that  
> > enable/disable computation of expensive aspects of the facet.
> > 
> > On Tue, Nov 22, 2011 at 3:17 PM, Michael Sick \<  
> > [michael.sick@serenesoftware.com](mailto:michael.sick@serenesoftware.com)\> wrote:
> > 
> > > I'm just starting to use the TermStatsFacet package and I was curious to  
> > > know if all of the stats (min/max/mean/...) are calculated when a  
> > > TermsStatsFacet response is prepared. If so, isn't this a bit of extra work  
> > > when a consumer will rarely want all of the stats and most often want one  
> > > or two?
> > > 
> > > Probably not a big concern if we stick with the small set of stats  
> > > offered but if the number of stats grows, it seems like it would be an  
> > > issue (vs. dealing with it as we deal with fields and specifying on the  
> > > request what we want in the response). Guess the same questions apply to  
> > > the base Stats facets as well.
> > > 
> > > Today, just curious if my understanding of how this works is correct as  
> > > it appears to work well for my current use case. Thanks!
> > > 
> > > --Mike

---

<div class="post-metadata">

**Author:** ![Michael\_Sick](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Michael\_Sick](https://discuss.elastic.co/u/Michael_Sick)\
**Post date:** [November 22, 2011, 3:52pm UTC](https://discuss.elastic.co/t/termstatsfacet-precalculated/5939/5 "2011-11-22T15:52:52Z")

</div>

My bad for just a quick glimpse at the scripts. I thought they were for  
custom stats (i.e. my average formula) vs. custom values (total, min, max  
of custom value).

Either way, I was curious if there would be a way to plugin new stats  
formulas. Say I wanted a 'range' function, it would be nice to have a way  
to easily define & register the function but it would have to be a bit more  
dynamic than adding getRange() to the StatsFacet.

On Tue, Nov 22, 2011 at 10:43 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> What do you mean by custom stat? You can plug in your own script to  
> provide a value (and then you get total, min, max for it). That script can  
> do whatever you want. If you want completely custom code, you can plug in  
> your own facet implementation, but its not that simple.
> 
> On Tue, Nov 22, 2011 at 4:37 PM, Michael Sick \<  
> [michael.sick@serenesoftware.com](mailto:michael.sick@serenesoftware.com)\> wrote:
> 
> > Thanks! That would work just fine (hopefully with an easy button to turn  
> > them all off and enable a few). If it's ok to pile on a question, I know we  
> > can do custom scripts to calculate a statistic but was curious if there was  
> > a good way to define/register a custom stat on the server side.
> > 
> > On Tue, Nov 22, 2011 at 8:54 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > 
> > > The idea with these type of concern is to add flags, that  
> > > enable/disable computation of expensive aspects of the facet.
> > > 
> > > On Tue, Nov 22, 2011 at 3:17 PM, Michael Sick \<  
> > > [michael.sick@serenesoftware.com](mailto:michael.sick@serenesoftware.com)\> wrote:
> > > 
> > > > I'm just starting to use the TermStatsFacet package and I was curious  
> > > > to know if all of the stats (min/max/mean/...) are calculated when a  
> > > > TermsStatsFacet response is prepared. If so, isn't this a bit of extra work  
> > > > when a consumer will rarely want all of the stats and most often want one  
> > > > or two?
> > > > 
> > > > Probably not a big concern if we stick with the small set of stats  
> > > > offered but if the number of stats grows, it seems like it would be an  
> > > > issue (vs. dealing with it as we deal with fields and specifying on the  
> > > > request what we want in the response). Guess the same questions apply to  
> > > > the base Stats facets as well.
> > > > 
> > > > Today, just curious if my understanding of how this works is correct as  
> > > > it appears to work well for my current use case. Thanks!
> > > > 
> > > > --Mike

---

<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:** [November 23, 2011, 3:44pm UTC](https://discuss.elastic.co/t/termstatsfacet-precalculated/5939/6 "2011-11-23T15:44:24Z")

</div>

Maybe we can talk about specific details of what you are after. Range can  
easily be done by adding a range filter to the facet (I assume you want the  
facet to be computed to a specific range).

On Tue, Nov 22, 2011 at 5:52 PM, Michael Sick \<  
[michael.sick@serenesoftware.com](mailto:michael.sick@serenesoftware.com)\> wrote:

> My bad for just a quick glimpse at the scripts. I thought they were for  
> custom stats (i.e. my average formula) vs. custom values (total, min, max  
> of custom value).
> 
> Either way, I was curious if there would be a way to plugin new stats  
> formulas. Say I wanted a 'range' function, it would be nice to have a way  
> to easily define & register the function but it would have to be a bit more  
> dynamic than adding getRange() to the StatsFacet.
> 
> On Tue, Nov 22, 2011 at 10:43 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > What do you mean by custom stat? You can plug in your own script to  
> > provide a value (and then you get total, min, max for it). That script can  
> > do whatever you want. If you want completely custom code, you can plug in  
> > your own facet implementation, but its not that simple.
> > 
> > On Tue, Nov 22, 2011 at 4:37 PM, Michael Sick \<  
> > [michael.sick@serenesoftware.com](mailto:michael.sick@serenesoftware.com)\> wrote:
> > 
> > > Thanks! That would work just fine (hopefully with an easy button to turn  
> > > them all off and enable a few). If it's ok to pile on a question, I know we  
> > > can do custom scripts to calculate a statistic but was curious if there was  
> > > a good way to define/register a custom stat on the server side.
> > > 
> > > On Tue, Nov 22, 2011 at 8:54 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > > 
> > > > The idea with these type of concern is to add flags, that  
> > > > enable/disable computation of expensive aspects of the facet.
> > > > 
> > > > On Tue, Nov 22, 2011 at 3:17 PM, Michael Sick \<  
> > > > [michael.sick@serenesoftware.com](mailto:michael.sick@serenesoftware.com)\> wrote:
> > > > 
> > > > > I'm just starting to use the TermStatsFacet package and I was curious  
> > > > > to know if all of the stats (min/max/mean/...) are calculated when a  
> > > > > TermsStatsFacet response is prepared. If so, isn't this a bit of extra work  
> > > > > when a consumer will rarely want all of the stats and most often want one  
> > > > > or two?
> > > > > 
> > > > > Probably not a big concern if we stick with the small set of stats  
> > > > > offered but if the number of stats grows, it seems like it would be an  
> > > > > issue (vs. dealing with it as we deal with fields and specifying on the  
> > > > > request what we want in the response). Guess the same questions apply to  
> > > > > the base Stats facets as well.
> > > > > 
> > > > > Today, just curious if my understanding of how this works is correct  
> > > > > as it appears to work well for my current use case. Thanks!
> > > > > 
> > > > > --Mike

---

<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:47am UTC](https://discuss.elastic.co/t/termstatsfacet-precalculated/5939/7 "2017-07-06T03:47:41Z")

</div>

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


