# Pre-compute aggregate metrics

**URL:** <https://discuss.elastic.co/t/pre-compute-aggregate-metrics/116100>\
**Category:** Elasticsearch\
**Created:** [January 18, 2018, 4:18pm UTC](https://discuss.elastic.co/t/pre-compute-aggregate-metrics/116100 "2018-01-18T16:18:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![akshayb](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@akshayb](https://discuss.elastic.co/u/akshayb)\
**Post date:** [January 18, 2018, 4:18pm UTC](https://discuss.elastic.co/t/pre-compute-aggregate-metrics/116100/1 "2018-01-18T16:18:06Z")

</div>

Hi,

I have documents representing orders with following format:  
{  
time: Date  
seller: String  
product : String  
price : Double  
}.  
These documents are generated all along the day. I have to create monthly reports showing overall sale for a seller with breakup by product. For current month sales till date should be shown.  
I will be using metric aggregation for this. Can I configure in Elastic Search that it keeps the sum of price precomputed for each month? Here if a new document for month x is added the sum should be updated adding the price in new document to the sum. Performing the sum every time I query will just slow down the query. The sum should be recomputed only if I apply filter.  
If the above case is not supported in Elastic Search, how can I best configure Elastic Search for my use case?  
Here are my thoughts:  
a) Have only one index for all the data.  
b) Derive year+month field for all documents.  
c) Index year+month, seller and product.  
Are there more factors I need to consider while designing my solution for elastic search?  
Is there a better approach to this problem ?

Thanks,  
-Akshay.

---

<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:** [February 15, 2018, 4:18pm UTC](https://discuss.elastic.co/t/pre-compute-aggregate-metrics/116100/2 "2018-02-15T16:18:09Z")

</div>

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