# Calculating multiple totals with facets

**URL:** <https://discuss.elastic.co/t/calculating-multiple-totals-with-facets/5191>\
**Category:** Elasticsearch\
**Created:** [August 18, 2011, 12:11pm UTC](https://discuss.elastic.co/t/calculating-multiple-totals-with-facets/5191 "2011-08-18T12:11:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicco](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicco/32/3106_2.png) [@nicco](https://discuss.elastic.co/u/nicco)\
**Post date:** [August 18, 2011, 12:11pm UTC](https://discuss.elastic.co/t/calculating-multiple-totals-with-facets/5191/1 "2011-08-18T12:11:27Z")

</div>

Hi everyone I have a question:

I have a data structure to map invoices and for each invoice i store  
its currency and the total amount:

{  
"document": {  
properties: {  
currencycode: {type: "string", index: "not\_analyzed",  
include\_in\_all: false},  
total: {type: "double"},  
....  
}  
}  
}

I would like to create a facets that will return me the totals for the  
invoices divided by currencies:

EUR : 20300  
USD : 13300  
.....

Is it possible?

Thanks!

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [August 18, 2011, 8:15pm UTC](https://discuss.elastic.co/t/calculating-multiple-totals-with-facets/5191/2 "2011-08-18T20:15:39Z")

</div>

Sounds like you want the term stats facets

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

currencycode will be the term facet and total will be the value\_field

--  
Ivan

On Thu, Aug 18, 2011 at 8:11 AM, nicco [nicco82@gmail.com](mailto:nicco82@gmail.com) wrote:

> Hi everyone I have a question:
> 
> I have a data structure to map invoices and for each invoice i store  
> its currency and the total amount:
> 
> {  
> "document": {  
> properties: {  
> currencycode: {type: "string", index: "not\_analyzed",  
> include\_in\_all: false},  
> total: {type: "double"},  
> ....  
> }  
> }  
> }
> 
> I would like to create a facets that will return me the totals for the  
> invoices divided by currencies:
> 
> EUR : 20300  
> USD : 13300  
> .....
> 
> Is it possible?
> 
> Thanks!

---

<div class="post-metadata">

**Author:** ![nicco](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicco/32/3106_2.png) [@nicco](https://discuss.elastic.co/u/nicco)\
**Post date:** [August 22, 2011, 8:43am UTC](https://discuss.elastic.co/t/calculating-multiple-totals-with-facets/5191/3 "2011-08-22T08:43:41Z")

</div>

Works perfectly thanks you!

On Aug 18, 10:15 pm, Ivan Brusic [i...@brusic.com](mailto:i...@brusic.com) wrote:

> Sounds like you want the term stats facetshttp://www.elasticsearch.org/guide/reference/api/search/facets/terms-...
> 
> currencycode will be the term facet and total will be the value\_field
> 
> --  
> Ivan
> 
> On Thu, Aug 18, 2011 at 8:11 AM, nicco [nicc...@gmail.com](mailto:nicc...@gmail.com) wrote:
> 
> > Hi everyone I have a question:
> 
> > I have a data structure to map invoices and for each invoice i store  
> > its currency and the total amount:
> 
> > {  
> > "document": {  
> > properties: {  
> > currencycode: {type: "string", index: "not\_analyzed",  
> > include\_in\_all: false},  
> > total: {type: "double"},  
> > ....  
> > }  
> > }  
> > }
> 
> > I would like to create a facets that will return me the totals for the  
> > invoices divided by currencies:
> 
> > EUR : 20300  
> > USD : 13300  
> > .....
> 
> > Is it possible?
> 
> > Thanks!

---

<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:56am UTC](https://discuss.elastic.co/t/calculating-multiple-totals-with-facets/5191/4 "2017-07-06T03:56:26Z")

</div>

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


