Watcher transform bytes to mb

how i transform bytes to mb ?

{
  "trigger": {
    "schedule": {
      "interval": "5m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "metrics-*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "size": 10,
          "query": {
            "bool": {
              "must": [
                {
                  "range": {
                    "kubernetes.node.memory.allocatable.bytes": {
                      "gt": 0
                    }
                  }
                },
                {
                  "script": {
                    "script": {
                      "source": "doc['kubernetes.node.memory.allocatable.bytes'].value > doc['kubernetes.node.memory.capacity.bytes'].value*9/100",
                      "params": {}
                    }
                  }
                }
              ],
              "filter": [
                {
                  "range": {
                    "@timestamp": {
                      "from": "{{ctx.trigger.scheduled_time}}||-{{ctx.metadata.time_range}}",
                      "to": "{{ctx.trigger.triggered_time}}"
                    }
                  }
                }
              ]
            }
          }
        }
      }
    }
  },
  "transform" : {
    "script" : "return [ 'memory_capacity_mb' : (ctx.payload.hits.hits.0._source.kubernetes.node.memory.capacity.bytes / 1024 / 1024) ]"
  },
  "condition": {
    "script": {
      "source": "return ctx.payload.hits.total > 0",
      "lang": "painless"
    }
  },
  "actions": {
    "send_email": {
      "email": {
        "profile": "standard",
        "priority": "high",
        "to": [
          "gabriel_sousa"
        ],
        "bcc": [
          "bernardo_meira"
        ],
        "subject": "Kubernetes - Node Memory Allocatable - WARNING",
        "body": {
          "html": """
          <p><br />

          <b>Execution time:</b>&nbsp;&nbsp;&nbsp;{{ctx.trigger.triggered_time}} (UTC)<br>
          <b>Alerting threshold:</b>&nbsp;&nbsp;&nbsp;{{ctx.metadata.threshold}}<br>
          <b>Check interval:</b>&nbsp;&nbsp;&nbsp;Watcher checks every {{ctx.metadata.trigger_schedule_interval_text}} for the previous {{ctx.metadata.time_range_text}} window if the threshold was exceeded.
        
          
          <p></p>
          <table stye="border: 1px solid white;">
          	<tbody>
          		<tr>
          		  <td style="width: 200px;background-color: #BEB2B2;border-radius: 10px;"><b>Timestamp</b></td>
          		  <td style="width: 310px;background-color: #BEB2B2;border-radius: 10px;"><b>Hostname/Node</b></td>
          		  <td style="width: 150px;background-color: #BEB2B2;border-radius: 10px;"><b>Allocatable Memory</b></td>
          		  <td style="width: 100px;background-color: #BEB2B2;border-radius: 10px;"><b>Total Memory</b></td>
          		</tr>
	       {{#ctx.payload.hits.hits}}			
          		<tr>
          		  <td style="width: 200px;background-color: #EEDFDE;border-radius: 10px;">{{_source.@timestamp}}</td>
          		  <td style="width: 310px;background-color: #EEDFDE;border-radius: 10px;">{{_source.kubernetes.node.name}}</td>
          		  <td style="width: 150px;background-color: #EEDFDE;border-radius: 10px;">{{_source.kubernetes.node.memory.allocatable.bytes }}</td>
          		  <td style="width: 100px;background-color: #EEDFDE;border-radius: 10px;">{{ctx.payload.memory_capacity_mb }}</td>
          		</tr>
          	</tbody>
          </table>
          
          {{/ctx.payload.hits.hits}}
          <p></p>
          """
        }
      }
    }
  },
  "metadata": {
    "trigger_schedule_interval_text": "5m",
    "throttle_period_text": "1 hour",
    "time_range_text": "5m",
    "time_range": "5m",
    "threshold": 1
  }
}

manage to find out

  "transform": {
    "script": {
      "source": "def transformed_hits = ctx.payload.hits.hits.stream().map(h -> {return ['timestamp': h._source['@timestamp'], 'node_name': h._source.kubernetes.node.name, 'capacity': Math.round(h._source.kubernetes.node.fs.capacity.bytes/1024/1024), 'used': Math.round(h._source.kubernetes.node.fs.used.bytes/1024/1024), 'available': Math.round(h._source.kubernetes.node.fs.available.bytes/1024/1024)]}).collect(Collectors.toList()); return ['transformed_hits': transformed_hits]",
      "lang": "painless"
    }
  }