# Statistical facet on multiple fields

**URL:** <https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431>\
**Category:** Elasticsearch\
**Created:** [October 10, 2010, 9:37pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431 "2010-10-10T21:37:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![zohar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zohar/32/3245_2.png) [@zohar](https://discuss.elastic.co/u/zohar)\
**Post date:** [October 10, 2010, 9:37pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/1 "2010-10-10T21:37:52Z")

</div>

Hi  
Is ther a way to produce a statistical facet ( sum avg min max etc )  
on multiplie fields at once.

Cheers  
Z

---

<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:** [October 10, 2010, 9:44pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/2 "2010-10-10T21:44:47Z")

</div>

You mean to have the statistical information accumulated across several  
fields, or execute it against different fields and have the results per  
field?

On Sun, Oct 10, 2010 at 11:37 PM, Zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com) wrote:

> Hi  
> Is ther a way to produce a statistical facet ( sum avg min max etc )  
> on multiplie fields at once.
> 
> Cheers  
> Z

---

<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:** [October 10, 2010, 10:48pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/3 "2010-10-10T22:48:33Z")

</div>

ok, I really can give you an answer for both:

I guess for the more obvious one, if you want to have stats on different  
fields and be computed differently, just execute different facet (with a  
different facet name) against each field.

If you want to get a combined statistical data on two fields, there is no  
"formal" way to do, but, you can get it by executing two stats facet on the  
two different fields, just _name the facets the same_. The results will be  
reduced into a single result. This is a "feature" that I did not plan for,  
to be honest, and discovered it by mistake :). A proper way to implement it  
is to have the ability to provide a list of fields to the stats facet, it  
will also be a tad faster this way. If you want, you can open a feature  
request for it (I already implemented something similar for terms facet).

-shay.banon

On Sun, Oct 10, 2010 at 11:44 PM, Shay Banon  
[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> You mean to have the statistical information accumulated across several  
> fields, or execute it against different fields and have the results per  
> field?
> 
> On Sun, Oct 10, 2010 at 11:37 PM, Zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com) wrote:
> 
> > Hi  
> > Is ther a way to produce a statistical facet ( sum avg min max etc )  
> > on multiplie fields at once.
> > 
> > Cheers  
> > Z

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [October 11, 2010, 1:40pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/4 "2010-10-11T13:40:33Z")

</div>

Hi Shay,

```
This is interesting.
So basically, by breaking json semantics one can achieve aggregation?

```

So, what happens if the facet is defined by an array with many objects?

Regards,  
Thigo Souza

On Sun, Oct 10, 2010 at 19:48, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> ok, I really can give you an answer for both:
> 
> I guess for the more obvious one, if you want to have stats on different  
> fields and be computed differently, just execute different facet (with a  
> different facet name) against each field.
> 
> If you want to get a combined statistical data on two fields, there is no  
> "formal" way to do, but, you can get it by executing two stats facet on the  
> two different fields, just _name the facets the same_. The results will be  
> reduced into a single result. This is a "feature" that I did not plan for,  
> to be honest, and discovered it by mistake :). A proper way to implement it  
> is to have the ability to provide a list of fields to the stats facet, it  
> will also be a tad faster this way. If you want, you can open a feature  
> request for it (I already implemented something similar for terms facet).
> 
> -shay.banon
> 
> On Sun, Oct 10, 2010 at 11:44 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)
> 
> > wrote:
> 
> > You mean to have the statistical information accumulated across several  
> > fields, or execute it against different fields and have the results per  
> > field?
> > 
> > On Sun, Oct 10, 2010 at 11:37 PM, Zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com) wrote:
> > 
> > > Hi  
> > > Is ther a way to produce a statistical facet ( sum avg min max etc )  
> > > on multiplie fields at once.
> > > 
> > > Cheers  
> > > Z

---

<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:** [October 11, 2010, 4:06pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/5 "2010-10-11T16:06:32Z")

</div>

Yea, this breaks json semantics since you need to define two facets under  
the same name. This "feature" was not planned, its just a matter of how the  
map reduce nature of facets work. If its going to be formal, then a proper  
json structure will need to be formalized. In any case, if there is a need  
for a facet over multiple fields (like stats), this feature can be  
added specifically for it.

On Mon, Oct 11, 2010 at 3:40 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com) wrote:

> Hi Shay,
> 
> ```
> This is interesting.
> So basically, by breaking json semantics one can achieve aggregation?
> 
> ```
> 
> So, what happens if the facet is defined by an array with many objects?
> 
> Regards,  
> Thigo Souza
> 
> On Sun, Oct 10, 2010 at 19:48, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > ok, I really can give you an answer for both:
> > 
> > I guess for the more obvious one, if you want to have stats on different  
> > fields and be computed differently, just execute different facet (with a  
> > different facet name) against each field.
> > 
> > If you want to get a combined statistical data on two fields, there is no  
> > "formal" way to do, but, you can get it by executing two stats facet on the  
> > two different fields, just _name the facets the same_. The results will be  
> > reduced into a single result. This is a "feature" that I did not plan for,  
> > to be honest, and discovered it by mistake :). A proper way to implement it  
> > is to have the ability to provide a list of fields to the stats facet, it  
> > will also be a tad faster this way. If you want, you can open a feature  
> > request for it (I already implemented something similar for terms facet).
> > 
> > -shay.banon
> > 
> > On Sun, Oct 10, 2010 at 11:44 PM, Shay Banon \<  
> > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > 
> > > You mean to have the statistical information accumulated across several  
> > > fields, or execute it against different fields and have the results per  
> > > field?
> > > 
> > > On Sun, Oct 10, 2010 at 11:37 PM, Zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com) wrote:
> > > 
> > > > Hi  
> > > > Is ther a way to produce a statistical facet ( sum avg min max etc )  
> > > > on multiplie fields at once.
> > > > 
> > > > Cheers  
> > > > Z

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [October 11, 2010, 5:23pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/6 "2010-10-11T17:23:08Z")

</div>

Hi Shay,

```
  But what happens if the facet is defined by an array with many

```

objects?

Regards

On Mon, Oct 11, 2010 at 13:06, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Yea, this breaks json semantics since you need to define two facets under  
> the same name. This "feature" was not planned, its just a matter of how the  
> map reduce nature of facets work. If its going to be formal, then a proper  
> json structure will need to be formalized. In any case, if there is a need  
> for a facet over multiple fields (like stats), this feature can be  
> added specifically for it.
> 
> On Mon, Oct 11, 2010 at 3:40 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> 
> > Hi Shay,
> > 
> > ```
> > This is interesting.
> > So basically, by breaking json semantics one can achieve aggregation?
> > 
> > ```
> > 
> > So, what happens if the facet is defined by an array with many objects?
> > 
> > Regards,  
> > Thigo Souza
> > 
> > On Sun, Oct 10, 2010 at 19:48, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> > 
> > > ok, I really can give you an answer for both:
> > > 
> > > I guess for the more obvious one, if you want to have stats on different  
> > > fields and be computed differently, just execute different facet (with a  
> > > different facet name) against each field.
> > > 
> > > If you want to get a combined statistical data on two fields, there is no  
> > > "formal" way to do, but, you can get it by executing two stats facet on the  
> > > two different fields, just _name the facets the same_. The results will be  
> > > reduced into a single result. This is a "feature" that I did not plan for,  
> > > to be honest, and discovered it by mistake :). A proper way to implement it  
> > > is to have the ability to provide a list of fields to the stats facet, it  
> > > will also be a tad faster this way. If you want, you can open a feature  
> > > request for it (I already implemented something similar for terms facet).
> > > 
> > > -shay.banon
> > > 
> > > On Sun, Oct 10, 2010 at 11:44 PM, Shay Banon \<  
> > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > 
> > > > You mean to have the statistical information accumulated across several  
> > > > fields, or execute it against different fields and have the results per  
> > > > field?
> > > > 
> > > > On Sun, Oct 10, 2010 at 11:37 PM, Zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com)wrote:
> > > > 
> > > > > Hi  
> > > > > Is ther a way to produce a statistical facet ( sum avg min max etc )  
> > > > > on multiplie fields at once.
> > > > > 
> > > > > Cheers  
> > > > > Z

---

<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:** [October 11, 2010, 5:32pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/7 "2010-10-11T17:32:40Z")

</div>

You mean the format of the facet expected is provided as an array? It won't  
work, the format mentioned in the docs is the only one supported. I  
mentioned in the previous email, if this is going to be a "formal" feature,  
then a different json structure needs to be defined.

On Mon, Oct 11, 2010 at 7:23 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com) wrote:

> Hi Shay,
> 
> ```
> But what happens if the facet is defined by an array with many
> 
> ```
> 
> objects?
> 
> Regards
> 
> On Mon, Oct 11, 2010 at 13:06, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > Yea, this breaks json semantics since you need to define two facets under  
> > the same name. This "feature" was not planned, its just a matter of how the  
> > map reduce nature of facets work. If its going to be formal, then a proper  
> > json structure will need to be formalized. In any case, if there is a need  
> > for a facet over multiple fields (like stats), this feature can be  
> > added specifically for it.
> > 
> > On Mon, Oct 11, 2010 at 3:40 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> > 
> > > Hi Shay,
> > > 
> > > ```
> > > This is interesting.
> > > So basically, by breaking json semantics one can achieve aggregation?
> > > 
> > > ```
> > > 
> > > So, what happens if the facet is defined by an array with many objects?
> > > 
> > > Regards,  
> > > Thigo Souza
> > > 
> > > On Sun, Oct 10, 2010 at 19:48, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> > > 
> > > > ok, I really can give you an answer for both:
> > > > 
> > > > I guess for the more obvious one, if you want to have stats on different  
> > > > fields and be computed differently, just execute different facet (with a  
> > > > different facet name) against each field.
> > > > 
> > > > If you want to get a combined statistical data on two fields, there is  
> > > > no "formal" way to do, but, you can get it by executing two stats facet on  
> > > > the two different fields, just _name the facets the same_. The results will  
> > > > be reduced into a single result. This is a "feature" that I did not plan  
> > > > for, to be honest, and discovered it by mistake :). A proper way to  
> > > > implement it is to have the ability to provide a list of fields to the stats  
> > > > facet, it will also be a tad faster this way. If you want, you can open a  
> > > > feature request for it (I already implemented something similar for terms  
> > > > facet).
> > > > 
> > > > -shay.banon
> > > > 
> > > > On Sun, Oct 10, 2010 at 11:44 PM, Shay Banon \<  
> > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > 
> > > > > You mean to have the statistical information accumulated across several  
> > > > > fields, or execute it against different fields and have the results per  
> > > > > field?
> > > > > 
> > > > > On Sun, Oct 10, 2010 at 11:37 PM, Zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com)wrote:
> > > > > 
> > > > > > Hi  
> > > > > > Is ther a way to produce a statistical facet ( sum avg min max etc )  
> > > > > > on multiplie fields at once.
> > > > > > 
> > > > > > Cheers  
> > > > > > Z

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [October 11, 2010, 7:53pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/8 "2010-10-11T19:53:40Z")

</div>

Ok, thanks!

On Mon, Oct 11, 2010 at 14:32, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> You mean the format of the facet expected is provided as an array? It won't  
> work, the format mentioned in the docs is the only one supported. I  
> mentioned in the previous email, if this is going to be a "formal" feature,  
> then a different json structure needs to be defined.
> 
> On Mon, Oct 11, 2010 at 7:23 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> 
> > Hi Shay,
> > 
> > ```
> > But what happens if the facet is defined by an array with many
> > 
> > ```
> > 
> > objects?
> > 
> > Regards
> > 
> > On Mon, Oct 11, 2010 at 13:06, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> > 
> > > Yea, this breaks json semantics since you need to define two facets under  
> > > the same name. This "feature" was not planned, its just a matter of how the  
> > > map reduce nature of facets work. If its going to be formal, then a proper  
> > > json structure will need to be formalized. In any case, if there is a need  
> > > for a facet over multiple fields (like stats), this feature can be  
> > > added specifically for it.
> > > 
> > > On Mon, Oct 11, 2010 at 3:40 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> > > 
> > > > Hi Shay,
> > > > 
> > > > ```
> > > > This is interesting.
> > > > So basically, by breaking json semantics one can achieve
> > > > 
> > > > ```
> > > > 
> > > > aggregation? So, what happens if the facet is defined by an array with many  
> > > > objects?
> > > > 
> > > > Regards,  
> > > > Thigo Souza
> > > > 
> > > > On Sun, Oct 10, 2010 at 19:48, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)
> > > > 
> > > > > wrote:
> > > > 
> > > > > ok, I really can give you an answer for both:
> > > > > 
> > > > > I guess for the more obvious one, if you want to have stats on  
> > > > > different fields and be computed differently, just execute different facet  
> > > > > (with a different facet name) against each field.
> > > > > 
> > > > > If you want to get a combined statistical data on two fields, there is  
> > > > > no "formal" way to do, but, you can get it by executing two stats facet on  
> > > > > the two different fields, just _name the facets the same_. The results will  
> > > > > be reduced into a single result. This is a "feature" that I did not plan  
> > > > > for, to be honest, and discovered it by mistake :). A proper way to  
> > > > > implement it is to have the ability to provide a list of fields to the stats  
> > > > > facet, it will also be a tad faster this way. If you want, you can open a  
> > > > > feature request for it (I already implemented something similar for terms  
> > > > > facet).
> > > > > 
> > > > > -shay.banon
> > > > > 
> > > > > On Sun, Oct 10, 2010 at 11:44 PM, Shay Banon \<  
> > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > 
> > > > > > You mean to have the statistical information accumulated across  
> > > > > > several fields, or execute it against different fields and have the results  
> > > > > > per field?
> > > > > > 
> > > > > > On Sun, Oct 10, 2010 at 11:37 PM, Zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com)wrote:
> > > > > > 
> > > > > > > Hi  
> > > > > > > Is ther a way to produce a statistical facet ( sum avg min max etc )  
> > > > > > > on multiplie fields at once.
> > > > > > > 
> > > > > > > Cheers  
> > > > > > > Z

---

<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:** [October 11, 2010, 8:25pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/9 "2010-10-11T20:25:35Z")

</div>

By the way, what facet type do you want this feature for? As I mentioned  
earlier in response to Zohar, a more optimized solution would be to be able  
to execute the facet itself against several fields. stats and terms facet  
are simple enough that doing aggregation across facets on different fields  
will work. Other facets, which accept several configuration options, might  
produce strange results (or even fail, like range facet and not using the  
same range elements).

On Mon, Oct 11, 2010 at 9:53 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com) wrote:

> Ok, thanks!
> 
> On Mon, Oct 11, 2010 at 14:32, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > You mean the format of the facet expected is provided as an array? It  
> > won't work, the format mentioned in the docs is the only one supported. I  
> > mentioned in the previous email, if this is going to be a "formal" feature,  
> > then a different json structure needs to be defined.
> > 
> > On Mon, Oct 11, 2010 at 7:23 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> > 
> > > Hi Shay,
> > > 
> > > ```
> > > But what happens if the facet is defined by an array with many
> > > 
> > > ```
> > > 
> > > objects?
> > > 
> > > Regards
> > > 
> > > On Mon, Oct 11, 2010 at 13:06, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> > > 
> > > > Yea, this breaks json semantics since you need to define two facets  
> > > > under the same name. This "feature" was not planned, its just a matter of  
> > > > how the map reduce nature of facets work. If its going to be formal, then a  
> > > > proper json structure will need to be formalized. In any case, if there is a  
> > > > need for a facet over multiple fields (like stats), this feature can be  
> > > > added specifically for it.
> > > > 
> > > > On Mon, Oct 11, 2010 at 3:40 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> > > > 
> > > > > Hi Shay,
> > > > > 
> > > > > ```
> > > > > This is interesting.
> > > > > So basically, by breaking json semantics one can achieve
> > > > > 
> > > > > ```
> > > > > 
> > > > > aggregation? So, what happens if the facet is defined by an array with many  
> > > > > objects?
> > > > > 
> > > > > Regards,  
> > > > > Thigo Souza
> > > > > 
> > > > > On Sun, Oct 10, 2010 at 19:48, Shay Banon \<  
> > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > 
> > > > > > ok, I really can give you an answer for both:
> > > > > > 
> > > > > > I guess for the more obvious one, if you want to have stats on  
> > > > > > different fields and be computed differently, just execute different facet  
> > > > > > (with a different facet name) against each field.
> > > > > > 
> > > > > > If you want to get a combined statistical data on two fields, there is  
> > > > > > no "formal" way to do, but, you can get it by executing two stats facet on  
> > > > > > the two different fields, just _name the facets the same_. The results will  
> > > > > > be reduced into a single result. This is a "feature" that I did not plan  
> > > > > > for, to be honest, and discovered it by mistake :). A proper way to  
> > > > > > implement it is to have the ability to provide a list of fields to the stats  
> > > > > > facet, it will also be a tad faster this way. If you want, you can open a  
> > > > > > feature request for it (I already implemented something similar for terms  
> > > > > > facet).
> > > > > > 
> > > > > > -shay.banon
> > > > > > 
> > > > > > On Sun, Oct 10, 2010 at 11:44 PM, Shay Banon \<  
> > > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > > 
> > > > > > > You mean to have the statistical information accumulated across  
> > > > > > > several fields, or execute it against different fields and have the results  
> > > > > > > per field?
> > > > > > > 
> > > > > > > On Sun, Oct 10, 2010 at 11:37 PM, Zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com)wrote:
> > > > > > > 
> > > > > > > > Hi  
> > > > > > > > Is ther a way to produce a statistical facet ( sum avg min max etc )  
> > > > > > > > on multiplie fields at once.
> > > > > > > > 
> > > > > > > > Cheers  
> > > > > > > > Z

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [October 11, 2010, 8:40pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/10 "2010-10-11T20:40:06Z")

</div>

Hi Shay,

Currently, for me, stats and terms is fine.

Regards

On Mon, Oct 11, 2010 at 17:25, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> By the way, what facet type do you want this feature for? As I mentioned  
> earlier in response to Zohar, a more optimized solution would be to be able  
> to execute the facet itself against several fields. stats and terms facet  
> are simple enough that doing aggregation across facets on different fields  
> will work. Other facets, which accept several configuration options, might  
> produce strange results (or even fail, like range facet and not using the  
> same range elements).
> 
> On Mon, Oct 11, 2010 at 9:53 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> 
> > Ok, thanks!
> > 
> > On Mon, Oct 11, 2010 at 14:32, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> > 
> > > You mean the format of the facet expected is provided as an array? It  
> > > won't work, the format mentioned in the docs is the only one supported. I  
> > > mentioned in the previous email, if this is going to be a "formal" feature,  
> > > then a different json structure needs to be defined.
> > > 
> > > On Mon, Oct 11, 2010 at 7:23 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> > > 
> > > > Hi Shay,
> > > > 
> > > > ```
> > > > But what happens if the facet is defined by an array with many
> > > > 
> > > > ```
> > > > 
> > > > objects?
> > > > 
> > > > Regards
> > > > 
> > > > On Mon, Oct 11, 2010 at 13:06, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)
> > > > 
> > > > > wrote:
> > > > 
> > > > > Yea, this breaks json semantics since you need to define two facets  
> > > > > under the same name. This "feature" was not planned, its just a matter of  
> > > > > how the map reduce nature of facets work. If its going to be formal, then a  
> > > > > proper json structure will need to be formalized. In any case, if there is a  
> > > > > need for a facet over multiple fields (like stats), this feature can be  
> > > > > added specifically for it.
> > > > > 
> > > > > On Mon, Oct 11, 2010 at 3:40 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> > > > > 
> > > > > > Hi Shay,
> > > > > > 
> > > > > > ```
> > > > > > This is interesting.
> > > > > > So basically, by breaking json semantics one can achieve
> > > > > > 
> > > > > > ```
> > > > > > 
> > > > > > aggregation? So, what happens if the facet is defined by an array with many  
> > > > > > objects?
> > > > > > 
> > > > > > Regards,  
> > > > > > Thigo Souza
> > > > > > 
> > > > > > On Sun, Oct 10, 2010 at 19:48, Shay Banon \<  
> > > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > > 
> > > > > > > ok, I really can give you an answer for both:
> > > > > > > 
> > > > > > > I guess for the more obvious one, if you want to have stats on  
> > > > > > > different fields and be computed differently, just execute different facet  
> > > > > > > (with a different facet name) against each field.
> > > > > > > 
> > > > > > > If you want to get a combined statistical data on two fields, there  
> > > > > > > is no "formal" way to do, but, you can get it by executing two stats facet  
> > > > > > > on the two different fields, just _name the facets the same_. The results  
> > > > > > > will be reduced into a single result. This is a "feature" that I did not  
> > > > > > > plan for, to be honest, and discovered it by mistake :). A proper way to  
> > > > > > > implement it is to have the ability to provide a list of fields to the stats  
> > > > > > > facet, it will also be a tad faster this way. If you want, you can open a  
> > > > > > > feature request for it (I already implemented something similar for terms  
> > > > > > > facet).
> > > > > > > 
> > > > > > > -shay.banon
> > > > > > > 
> > > > > > > On Sun, Oct 10, 2010 at 11:44 PM, Shay Banon \<  
> > > > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > > > 
> > > > > > > > You mean to have the statistical information accumulated across  
> > > > > > > > several fields, or execute it against different fields and have the results  
> > > > > > > > per field?
> > > > > > > > 
> > > > > > > > On Sun, Oct 10, 2010 at 11:37 PM, Zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com)wrote:
> > > > > > > > 
> > > > > > > > > Hi  
> > > > > > > > > Is ther a way to produce a statistical facet ( sum avg min max etc  
> > > > > > > > > )  
> > > > > > > > > on multiplie fields at once.
> > > > > > > > > 
> > > > > > > > > Cheers  
> > > > > > > > > Z

---

<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:** [October 11, 2010, 10:51pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/11 "2010-10-11T22:51:16Z")

</div>

cool, ok. I will work on adding multi field support for stats. The two are  
the ones the make most sense to do.

On Mon, Oct 11, 2010 at 10:40 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:

> Hi Shay,
> 
> Currently, for me, stats and terms is fine.
> 
> Regards
> 
> On Mon, Oct 11, 2010 at 17:25, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > By the way, what facet type do you want this feature for? As I mentioned  
> > earlier in response to Zohar, a more optimized solution would be to be able  
> > to execute the facet itself against several fields. stats and terms facet  
> > are simple enough that doing aggregation across facets on different fields  
> > will work. Other facets, which accept several configuration options, might  
> > produce strange results (or even fail, like range facet and not using the  
> > same range elements).
> > 
> > On Mon, Oct 11, 2010 at 9:53 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> > 
> > > Ok, thanks!
> > > 
> > > On Mon, Oct 11, 2010 at 14:32, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> > > 
> > > > You mean the format of the facet expected is provided as an array? It  
> > > > won't work, the format mentioned in the docs is the only one supported. I  
> > > > mentioned in the previous email, if this is going to be a "formal" feature,  
> > > > then a different json structure needs to be defined.
> > > > 
> > > > On Mon, Oct 11, 2010 at 7:23 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> > > > 
> > > > > Hi Shay,
> > > > > 
> > > > > ```
> > > > > But what happens if the facet is defined by an array with many
> > > > > 
> > > > > ```
> > > > > 
> > > > > objects?
> > > > > 
> > > > > Regards
> > > > > 
> > > > > On Mon, Oct 11, 2010 at 13:06, Shay Banon \<  
> > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > 
> > > > > > Yea, this breaks json semantics since you need to define two facets  
> > > > > > under the same name. This "feature" was not planned, its just a matter of  
> > > > > > how the map reduce nature of facets work. If its going to be formal, then a  
> > > > > > proper json structure will need to be formalized. In any case, if there is a  
> > > > > > need for a facet over multiple fields (like stats), this feature can be  
> > > > > > added specifically for it.
> > > > > > 
> > > > > > On Mon, Oct 11, 2010 at 3:40 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> > > > > > 
> > > > > > > Hi Shay,
> > > > > > > 
> > > > > > > ```
> > > > > > > This is interesting.
> > > > > > > So basically, by breaking json semantics one can achieve
> > > > > > > 
> > > > > > > ```
> > > > > > > 
> > > > > > > aggregation? So, what happens if the facet is defined by an array with many  
> > > > > > > objects?
> > > > > > > 
> > > > > > > Regards,  
> > > > > > > Thigo Souza
> > > > > > > 
> > > > > > > On Sun, Oct 10, 2010 at 19:48, Shay Banon \<  
> > > > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > > > 
> > > > > > > > ok, I really can give you an answer for both:
> > > > > > > > 
> > > > > > > > I guess for the more obvious one, if you want to have stats on  
> > > > > > > > different fields and be computed differently, just execute different facet  
> > > > > > > > (with a different facet name) against each field.
> > > > > > > > 
> > > > > > > > If you want to get a combined statistical data on two fields, there  
> > > > > > > > is no "formal" way to do, but, you can get it by executing two stats facet  
> > > > > > > > on the two different fields, just _name the facets the same_. The results  
> > > > > > > > will be reduced into a single result. This is a "feature" that I did not  
> > > > > > > > plan for, to be honest, and discovered it by mistake :). A proper way to  
> > > > > > > > implement it is to have the ability to provide a list of fields to the stats  
> > > > > > > > facet, it will also be a tad faster this way. If you want, you can open a  
> > > > > > > > feature request for it (I already implemented something similar for terms  
> > > > > > > > facet).
> > > > > > > > 
> > > > > > > > -shay.banon
> > > > > > > > 
> > > > > > > > On Sun, Oct 10, 2010 at 11:44 PM, Shay Banon \<  
> > > > > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > > > > 
> > > > > > > > > You mean to have the statistical information accumulated across  
> > > > > > > > > several fields, or execute it against different fields and have the results  
> > > > > > > > > per field?
> > > > > > > > > 
> > > > > > > > > On Sun, Oct 10, 2010 at 11:37 PM, Zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com)wrote:
> > > > > > > > > 
> > > > > > > > > > Hi  
> > > > > > > > > > Is ther a way to produce a statistical facet ( sum avg min max etc  
> > > > > > > > > > )  
> > > > > > > > > > on multiplie fields at once.
> > > > > > > > > > 
> > > > > > > > > > Cheers  
> > > > > > > > > > Z

---

<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:** [October 17, 2010, 2:23pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/12 "2010-10-17T14:23:36Z")

</div>

Just pushed support for statistical facet on more than one field:  
[Statistical Facet: Allow to compute statistical facets on more than one field · Issue #436 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/issue/436).

On Tue, Oct 12, 2010 at 12:51 AM, Shay Banon  
[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> cool, ok. I will work on adding multi field support for stats. The two are  
> the ones the make most sense to do.
> 
> On Mon, Oct 11, 2010 at 10:40 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> 
> > Hi Shay,
> > 
> > Currently, for me, stats and terms is fine.
> > 
> > Regards
> > 
> > On Mon, Oct 11, 2010 at 17:25, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> > 
> > > By the way, what facet type do you want this feature for? As I mentioned  
> > > earlier in response to Zohar, a more optimized solution would be to be able  
> > > to execute the facet itself against several fields. stats and terms facet  
> > > are simple enough that doing aggregation across facets on different fields  
> > > will work. Other facets, which accept several configuration options, might  
> > > produce strange results (or even fail, like range facet and not using the  
> > > same range elements).
> > > 
> > > On Mon, Oct 11, 2010 at 9:53 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> > > 
> > > > Ok, thanks!
> > > > 
> > > > On Mon, Oct 11, 2010 at 14:32, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)
> > > > 
> > > > > wrote:
> > > > 
> > > > > You mean the format of the facet expected is provided as an array? It  
> > > > > won't work, the format mentioned in the docs is the only one supported. I  
> > > > > mentioned in the previous email, if this is going to be a "formal" feature,  
> > > > > then a different json structure needs to be defined.
> > > > > 
> > > > > On Mon, Oct 11, 2010 at 7:23 PM, Thiago Souza [tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)wrote:
> > > > > 
> > > > > > Hi Shay,
> > > > > > 
> > > > > > ```
> > > > > > But what happens if the facet is defined by an array with many
> > > > > > 
> > > > > > ```
> > > > > > 
> > > > > > objects?
> > > > > > 
> > > > > > Regards
> > > > > > 
> > > > > > On Mon, Oct 11, 2010 at 13:06, Shay Banon \<  
> > > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > > 
> > > > > > > Yea, this breaks json semantics since you need to define two facets  
> > > > > > > under the same name. This "feature" was not planned, its just a matter of  
> > > > > > > how the map reduce nature of facets work. If its going to be formal, then a  
> > > > > > > proper json structure will need to be formalized. In any case, if there is a  
> > > > > > > need for a facet over multiple fields (like stats), this feature can be  
> > > > > > > added specifically for it.
> > > > > > > 
> > > > > > > On Mon, Oct 11, 2010 at 3:40 PM, Thiago Souza \<[tcostasouza@gmail.com](mailto:tcostasouza@gmail.com)
> > > > > > > 
> > > > > > > > wrote:
> > > > > > > 
> > > > > > > > Hi Shay,
> > > > > > > > 
> > > > > > > > ```
> > > > > > > > This is interesting.
> > > > > > > > So basically, by breaking json semantics one can achieve
> > > > > > > > 
> > > > > > > > ```
> > > > > > > > 
> > > > > > > > aggregation? So, what happens if the facet is defined by an array with many  
> > > > > > > > objects?
> > > > > > > > 
> > > > > > > > Regards,  
> > > > > > > > Thigo Souza
> > > > > > > > 
> > > > > > > > On Sun, Oct 10, 2010 at 19:48, Shay Banon \<  
> > > > > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > > > > 
> > > > > > > > > ok, I really can give you an answer for both:
> > > > > > > > > 
> > > > > > > > > I guess for the more obvious one, if you want to have stats on  
> > > > > > > > > different fields and be computed differently, just execute different facet  
> > > > > > > > > (with a different facet name) against each field.
> > > > > > > > > 
> > > > > > > > > If you want to get a combined statistical data on two fields, there  
> > > > > > > > > is no "formal" way to do, but, you can get it by executing two stats facet  
> > > > > > > > > on the two different fields, just _name the facets the same_. The results  
> > > > > > > > > will be reduced into a single result. This is a "feature" that I did not  
> > > > > > > > > plan for, to be honest, and discovered it by mistake :). A proper way to  
> > > > > > > > > implement it is to have the ability to provide a list of fields to the stats  
> > > > > > > > > facet, it will also be a tad faster this way. If you want, you can open a  
> > > > > > > > > feature request for it (I already implemented something similar for terms  
> > > > > > > > > facet).
> > > > > > > > > 
> > > > > > > > > -shay.banon
> > > > > > > > > 
> > > > > > > > > On Sun, Oct 10, 2010 at 11:44 PM, Shay Banon \<  
> > > > > > > > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > > > > > > > 
> > > > > > > > > > You mean to have the statistical information accumulated across  
> > > > > > > > > > several fields, or execute it against different fields and have the results  
> > > > > > > > > > per field?
> > > > > > > > > > 
> > > > > > > > > > On Sun, Oct 10, 2010 at 11:37 PM, Zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com)wrote:
> > > > > > > > > > 
> > > > > > > > > > > Hi  
> > > > > > > > > > > Is ther a way to produce a statistical facet ( sum avg min max  
> > > > > > > > > > > etc )  
> > > > > > > > > > > on multiplie fields at once.
> > > > > > > > > > > 
> > > > > > > > > > > Cheers  
> > > > > > > > > > > Z

---

<div class="post-metadata">

**Author:** ![zohar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zohar/32/3245_2.png) [@zohar](https://discuss.elastic.co/u/zohar)\
**Post date:** [November 25, 2010, 3:09pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/13 "2010-11-25T15:09:58Z")

</div>

Hi  
Coming back to this question having spent a bit of time playing around.  
What I am trying to achieve :

we have an index with documents that look like :  
{  
currency:'USD',  
product:'toaster',  
value: 23.4  
},  
{  
currency:'GBP',  
product:'toaster',  
value: 13.4  
}

I want to produce factes for 'currency' & 'product' where the value of each term is not a count , its a sum of values.

The expected result would be something like :

facets": {  
"currencyFacet": {  
"\_type": "terms",  
"\_field": "currency",  
"terms": [  
{  
"term": "GBP",  
"count": 1,  
"value": 13.4  
},  
{  
"term": "USD",  
"count": 1,  
"value": 23.4  
}  
}  
]  
},  
"productFacet": {  
"\_type": "terms",  
"\_field": "product",  
"terms": [  
{  
"term": "toaster",  
"count": 2,  
"value":36.8

```
			},

```

]  
}  
}  
}

this aggregate some numeric field by a variety of non numeric terms is very very common for us.

Any ideas ?

Cheers  
Z

---

<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 25, 2010, 6:57pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/14 "2010-11-25T18:57:22Z")

</div>

There isn't a built in one to do that, but sounds good, open a feature  
request?

On Thu, Nov 25, 2010 at 5:09 PM, zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com) wrote:

> Hi  
> Coming back to this question having spent a bit of time playing around.  
> What I am trying to achieve :
> 
> we have an index with documents that look like :  
> {  
> currency:'USD',  
> product:'toaster',  
> value: 23.4  
> },  
> {  
> currency:'GBP',  
> product:'toaster',  
> value: 13.4  
> }
> 
> I want to produce factes for 'currency' & 'product' where the value of  
> each  
> term is not a count , its a sum of values.
> 
> The expected result would be something like :
> 
> facets": {  
> "currencyFacet": {  
> "\_type": "terms",  
> "\_field": "currency",  
> "terms": [  
> {  
> "term": "GBP",  
> "count": 1,  
> "value": 13.4  
> },  
> {  
> "term": "USD",  
> "count": 1,  
> "value": 23.4  
> }  
> }  
> ]  
> },  
> "productFacet": {  
> "\_type": "terms",  
> "\_field": "product",  
> "terms": [  
> {  
> "term": "toaster",  
> "count": 2,  
> "value":36.8
> 
> ```
> },
> 
> ```
> 
> ]  
> }  
> }  
> }
> 
> this aggregate some numeric field by a variety of non numeric terms is very  
> very common for us.
> 
> Any ideas ?
> 
> Cheers  
> Z
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Statistical-facet-on-multiple-fields-tp1676993p1967528.html](http://elasticsearch-users.115913.n3.nabble.com/Statistical-facet-on-multiple-fields-tp1676993p1967528.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![zohar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zohar/32/3245_2.png) [@zohar](https://discuss.elastic.co/u/zohar)\
**Post date:** [November 25, 2010, 7:37pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/15 "2010-11-25T19:37:43Z")

</div>

Created - [https://github.com/elasticsearch/elasticsearch/issues/#issue/539](https://github.com/elasticsearch/elasticsearch/issues/#issue/539) looking fwd to it.

Thanks  
Z

---

<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 25, 2010, 7:50pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/16 "2010-11-25T19:50:28Z")

</div>

Just wanted to make sure regarding one aspect of the feature, does each  
document consist of single values of currency and price, or can have several  
of those? If its the latter, then the feature is more complex to implement  
and requires some other features before hand... (the ordering of the fields  
within a doc when loaded for facets is not maintained).

On Thu, Nov 25, 2010 at 9:37 PM, zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com) wrote:

> Created - [Issues · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/#issue/539)  
> looking fwd to it.
> 
> ## Thanks Z
> 
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Statistical-facet-on-multiple-fields-tp1676993p1969052.html](http://elasticsearch-users.115913.n3.nabble.com/Statistical-facet-on-multiple-fields-tp1676993p1969052.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![zohar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zohar/32/3245_2.png) [@zohar](https://discuss.elastic.co/u/zohar)\
**Post date:** [November 26, 2010, 11:16am UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/17 "2010-11-26T11:16:55Z")

</div>

Yes they are single values

---

<div class="post-metadata">

**Author:** ![harelba](https://avatars.discourse-cdn.com/v4/letter/h/f19dbf/32.png) [@harelba](https://discuss.elastic.co/u/harelba)\
**Post date:** [December 27, 2010, 4:27pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/18 "2010-12-27T16:27:51Z")

</div>

Hi,

I've been looking for a way to perform aggregations similar to the ones talked about in this thread, grouping the data according to an arbitrary set or fields (or better yet - an expression).

The ScriptHistogramFacet seemed like a good choice, allowing the key to actually be a "key\_script", and skipping the "bucketing" stage. I thought that this would allow me to achieve this kind of aggregations, but then I saw that ScriptHistogramFacetCollector.doCollect() relies on the fact that value returned from key\_script has to be of type Number even if the interval==0. I know that currently you're using LongLong maps, but If it would have accepted other types as well (at least strings), that would have been really great.

Am I getting it wrong? Is there a good way to do that? Your help would be much appreciated.

Thanks,  
RL

btw, it would have been totally cool if the data collected by the StatisticalFacet would be integrated into the HistogramFacet (and its scripted brother). The StatisticalFacet is great, but often-times the statistical data is required per some kind of "group", and not only on some kind of filter over the whole data.

---

<div class="post-metadata">

**Author:** ![harelba](https://avatars.discourse-cdn.com/v4/letter/h/f19dbf/32.png) [@harelba](https://discuss.elastic.co/u/harelba)\
**Post date:** [December 28, 2010, 12:05pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/19 "2010-12-28T12:05:13Z")

</div>

Hi,

I've been looking for a way to perform aggregations similar to the  
ones talked about in this thread, grouping the data according to an  
arbitrary set or fields (or better yet - an expression).

The ScriptHistogramFacet seemed like a good choice, allowing the key  
to actually be a "key\_script", and skipping the "bucketing" stage. I  
thought that this would allow me to achieve this kind of aggregations,  
but then I saw that ScriptHistogramFacetCollector.doCollect() relies  
on the fact that value returned from key\_script has to be of type  
Number even if the interval==0. I know that currently you're using  
LongLong maps, but If it would have accepted other types as well (at  
least strings), that would have been really great.

Am I getting it wrong? Is there a good way to do that? Your help would  
be much appreciated.

Thanks,  
RL

btw, it would have been totally cool if the data collected by the  
StatisticalFacet would be integrated into the HistogramFacet (and its  
scripted brother). The StatisticalFacet is great, but often-times the  
statistical data is required per some kind of "group", and not only on  
some kind of filter over the whole data.

---

<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:** [December 28, 2010, 6:35pm UTC](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431/20 "2010-12-28T18:35:41Z")

</div>

It make sense, what you are after. The main challenge with facets is the  
fact that they can get really interesting once you start to combine them (as  
is the case in this thread with terms and stats). The problem is that those  
facet implementation are highly optimized for the simple reason that they  
might end up running over 100s of millions of docs. And implementing all the  
combinations in a generic fashion is certainly possible, but will incur a  
performance overhead (both in computation, but even more in serialization  
over network).

One of the things lined up for 0.15 is to do some refactoring in facets and  
make them more pluggable. Once thats out of the way, then people can write  
their own facet implementations.

Of couse, there should be a good out of the box set of facets that comes  
with ES. My current line of thought is that there will simply be a lot of  
facet types, all heavily optimized. There will be a terms\_stats, and  
date\_histogram, and others. I don't mind implementing all of those and have  
them as past of ES. Hopefully the community will help with it (or at the  
very least, help with coming up with good names for them 🙂 ), so you will  
get a really rich and heavily optimized set of facets.

-shay.banon

On Tue, Dec 28, 2010 at 2:05 PM, harelba [harelba@gmail.com](mailto:harelba@gmail.com) wrote:

> Hi,
> 
> I've been looking for a way to perform aggregations similar to the  
> ones talked about in this thread, grouping the data according to an  
> arbitrary set or fields (or better yet - an expression).
> 
> The ScriptHistogramFacet seemed like a good choice, allowing the key  
> to actually be a "key\_script", and skipping the "bucketing" stage. I  
> thought that this would allow me to achieve this kind of aggregations,  
> but then I saw that ScriptHistogramFacetCollector.doCollect() relies  
> on the fact that value returned from key\_script has to be of type  
> Number even if the interval==0. I know that currently you're using  
> LongLong maps, but If it would have accepted other types as well (at  
> least strings), that would have been really great.
> 
> Am I getting it wrong? Is there a good way to do that? Your help would  
> be much appreciated.
> 
> Thanks,  
> RL
> 
> btw, it would have been totally cool if the data collected by the  
> StatisticalFacet would be integrated into the HistogramFacet (and its  
> scripted brother). The StatisticalFacet is great, but often-times the  
> statistical data is required per some kind of "group", and not only on  
> some kind of filter over the whole data.

[Next page](https://discuss.elastic.co/t/statistical-facet-on-multiple-fields/3431.md?page=2)
