code: public static function map($query = [], callable $callback = null, $limit = -1)
      {
          if ($query instanceof QueryBuilder) {
              $query = $query->build();
          }
  
          $query['from'] = Arr::get($query, 'from', 0);
          $query['size'] = Arr::get($query, 'size', 50);
  
          $i = 0;
          $models = static::search($query);
          $total = $models->getTotal();
          while ($models) {
              foreach ($models as $model) {
                  if ($callback) {
                      $callback($model);
                  }
                  $i++;
              }
  
              $query['from'] += $query['size'];
  
              if ($i >= $total || ($limit > 0 && $i >= $limit)) {
                  break;
              }
  
              $models = static::search($query);
          }
  
          return $total;
      }
docs: Apply the callback to the documents of the given query.
  
  @param QueryBuilder|array $query
  @param callable $callback
  @param int $limit
  @return int hits.total