Pre-compute aggregate metrics

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 ?


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