I am performing an aggregation on our company daily data stream in Elastic. I am bucketing the data by an "mid: field, and summing the "amount" field in the payload. It looks like this:
{ "aggs": { "tpv": { "terms": { "field": "payload.mid", "order" : { "total_volume" : "desc" } }, "aggs": { "total_volume": { "sum": { "field": "payload.usd_amt" } } } } } }
When I run the above aggregation, I see response data like this:
{
"_id": "cal_tpv_agg_watch_0-2016-03-21T13:20:56.372Z",
"result": {
"execution_time": "2016-03-21T13:20:56.372Z",
"execution_duration": 20,
"input": {
"aggregations": {
"tpv": {
"buckets": [
{
"doc_count": 146,
"total_volume": {
"value": 1559432
},
"key": "12347"
},
{
"doc_count": 120,
"total_volume": {
"value": 1239380
},
"key": "12352"
}
]
}
I use an extract statement to put "aggregations.tpv.buckets" into ctx.payload.
I'd like to save the daily aggregation buckets data to another index (so that later we can roll up the data into weekly, monthly, or yearly amounts). I am doing this by using an index action to put the aggregation into another index.
Does anyone have an example of transforming the "ctx.payload.tpv.buckets" data to the payload "_doc" field to take advantage of multi-document indexing specified in Actions - Multi-doc support
What's the best way of re-indexing aggregated data for later use?
Thanks, beckerdo