**{ "size": 2, "source": { "includes": [ "room","eta","etd","quantity"] }, "query": { "bool": { "must": [ { "range": { "eta": { "gte": "2017-11-01", "lte": "2017-11-01", "time_zone": "+08:00" } } } ] } }, "aggregations": { "type": { "terms": { "field": "room" }, "aggregations": { "checkin": { "date_histogram": { "field": "eta", "time_zone": "+08:00", "interval": "1d", "format" : "yyyy-MM-dd" }, "**code
"sumq": { "scripted_metric": { "init_script" : "params._agg.transactions = []", "map_script" : "params._agg.transactions.add(doc.etd.value+'_'+doc.eta.value+'_'+doc.quantity.value)" } }
** } } } } }, "sort": { "eta": { "order": "asc" }} }**_orm