Best approach to totals when aggregating many documents

We're want to use elasticsearch to create reports based on financial data.
Currently we are still creating our mappings. Now we are not certain which approach is best.
We want to compute different totals in our report and the value field of each document should only be included in a certain total based on the "nature" of this document (e.g. expenses for cloth => sum(cloth_expenses); expenses for food => sum(food_expenses) etc.).

  1. First idea was to create one field that holds the value we want to total up and have several boolean fields that indicate which sum this documents value should be added to:
    .subAggregation(AggregationBuilders.terms("myAgg")
    .field("someBooleanField")
    .subAggregation(AggregationBuilders.sum("sumMyField").field("myField").missing("0"))
    .subAggregation(AggregationBuilders.terms("myOtherAgg")
    .field("anotherBooleanField")
    .subAggregation(AggregationBuilders.sum("sumMyField").field("myField").missing("0"))

  2. Second idea was to create one field that holds the value we want to total up and use type to indicate to which sum we need to add this documents value. Haven't tried it yet.

Now we are afraid that filtering/selecting the value based on another field might be too expensive we are wondering now, if we should have several value fields and place the value in the correct filed on indexing time.

How does elasticsearch handle such requests, will filtering/selecting have a huge impact on performace?
Is there a best approach to this problem?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.