# Computing sums with a custom facet handler

**URL:** <https://discuss.elastic.co/t/computing-sums-with-a-custom-facet-handler/9068>\
**Category:** Elasticsearch\
**Created:** [September 19, 2012, 7:02pm UTC](https://discuss.elastic.co/t/computing-sums-with-a-custom-facet-handler/9068 "2012-09-19T19:02:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dallan\_Quass](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@Dallan\_Quass](https://discuss.elastic.co/u/Dallan_Quass)\
**Post date:** [September 19, 2012, 7:02pm UTC](https://discuss.elastic.co/t/computing-sums-with-a-custom-facet-handler/9068/1 "2012-09-19T19:02:49Z")

</div>

How difficult would it be to compute a sum by writing a custom facet  
handler? For example, the terms facet handler computes a count of the  
number of documents with each value of a specified field; instead of  
counting the number of documents, for each document I want to look up the  
value of another field and sum it. Another way to look at this is: the  
terms facet handler allows me to compute "select X, count(\*) from T group  
by X" and I want to compute "select X, sum(Y) from T group by X". I've  
started looking over the code in  
[https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/search/facet](https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/search/facet)  
Any pointers to help me get started?

--

---

<div class="post-metadata">

**Author:** ![Max\_Melentiev](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@Max\_Melentiev](https://discuss.elastic.co/u/Max_Melentiev)\
**Post date:** [September 19, 2012, 7:09pm UTC](https://discuss.elastic.co/t/computing-sums-with-a-custom-facet-handler/9068/2 "2012-09-19T19:09:23Z")

</div>

[http://www.elasticsearch.org/guide/reference/api/search/facets/statistical-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/statistical-facet.html)  
should work for you.  
it returns 'total' it`s just a sum

--  
View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Computing-sums-with-a-custom-facet-handler-tp4022902p4022903.html](http://elasticsearch-users.115913.n3.nabble.com/Computing-sums-with-a-custom-facet-handler-tp4022902p4022903.html)  
Sent from the ElasticSearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<div class="post-metadata">

**Author:** ![Craig\_Brown](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@Craig\_Brown](https://discuss.elastic.co/u/Craig_Brown)\
**Post date:** [September 19, 2012, 8:43pm UTC](https://discuss.elastic.co/t/computing-sums-with-a-custom-facet-handler/9068/3 "2012-09-19T20:43:48Z")

</div>

I don't think it's too difficult. I'll see if I can dig up some information  
for you. I think there needs to be some "facet handler" to integrate the  
new facet into the system. I think they are re-writing the faceting code  
for .20.

- Craig

On Wed, Sep 19, 2012 at 1:02 PM, Dallan Quass [dallan@gmail.com](mailto:dallan@gmail.com) wrote:

> How difficult would it be to compute a sum by writing a custom facet  
> handler? For example, the terms facet handler computes a count of the  
> number of documents with each value of a specified field; instead of  
> counting the number of documents, for each document I want to look up the  
> value of another field and sum it. Another way to look at this is: the  
> terms facet handler allows me to compute "select X, count(\*) from T group  
> by X" and I want to compute "select X, sum(Y) from T group by X". I've  
> started looking over the code in  
> [https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/search/facet](https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/search/facet)  
> Any pointers to help me get started?
> 
> --

--  
…  
CRAIG BROWN  
youwho, Inc.

[www.youwho.com](http://www.youwho.com)

T: 801.855. 0921  
M: 801.913. 0939

--

---

<div class="post-metadata">

**Author:** ![Max\_Melentiev](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@Max\_Melentiev](https://discuss.elastic.co/u/Max_Melentiev)\
**Post date:** [September 20, 2012, 4:15am UTC](https://discuss.elastic.co/t/computing-sums-with-a-custom-facet-handler/9068/4 "2012-09-20T04:15:39Z")

</div>

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

should work for you.  
it returns 'total' it`s just a sum  
But i didn't find how to evaluate just selected values. Ex. i don't need  
sum\_of\_sqares

On Thursday, September 20, 2012 1:02:49 AM UTC+6, Dallan Quass wrote:

> How difficult would it be to compute a sum by writing a custom facet  
> handler? For example, the terms facet handler computes a count of the  
> number of documents with each value of a specified field; instead of  
> counting the number of documents, for each document I want to look up the  
> value of another field and sum it. Another way to look at this is: the  
> terms facet handler allows me to compute "select X, count(\*) from T group  
> by X" and I want to compute "select X, sum(Y) from T group by X". I've  
> started looking over the code in  
> [https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/search/facet](https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/search/facet)  
> Any pointers to help me get started?

--

---

<div class="post-metadata">

**Author:** ![Dallan\_Quass](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@Dallan\_Quass](https://discuss.elastic.co/u/Dallan_Quass)\
**Post date:** [September 21, 2012, 11:55pm UTC](https://discuss.elastic.co/t/computing-sums-with-a-custom-facet-handler/9068/5 "2012-09-21T23:55:25Z")

</div>

Thank you! That looks that will give me a good start.

Dallan

On Sep 19, 2012, at 2:09 PM, Max Melentiev [printercu@gmail.com](mailto:printercu@gmail.com) wrote:

> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/statistical-facet.html)  
> should work for you.  
> it returns 'total' it`s just a sum
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Computing-sums-with-a-custom-facet-handler-tp4022902p4022903.html](http://elasticsearch-users.115913.n3.nabble.com/Computing-sums-with-a-custom-facet-handler-tp4022902p4022903.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --

--

---

<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:11am UTC](https://discuss.elastic.co/t/computing-sums-with-a-custom-facet-handler/9068/6 "2017-07-06T03:11:50Z")

</div>


