We execute the scripted_metric aggregation in four different stages: the init stage, the map stage, the combine stage, and the reduce stage. The corresponding script parameters are as follows:
- init_script: Optional parameter. A script for initialization, including an object named state to store the changes in the shard level.
- map_script: Required parameter. A script to perform at the document level if the document is included in the aggregation.
- combine_script: Required parameter. A script to perform in the shard level when all the documents are collected within a shard node. Finally, a value or an object is returned to the coordinating node.
- reduce_script: Required parameter. A script to perform in the coordinating node ...