private function indexJobs() { $this->total = DB::table('phpjob_jobs')->count(); $this->processed = 0; $this->write('info', '=== [JOBS] ==='); Job::chunk($this->batch, function ($jobs) { $offset = $this->processed; $this->processed += count($jobs); $documents = []; foreach ($jobs as $job) { $document = $this->elastica->createDocument([], 'jobs', 'activehire', $job->jobid); $document = $this->jobTransformer->toDocument($job, $document); $documents[] = $document; } $this->elastica->addDocuments($documents); $this->write('info', 'Indexed jobs from ' . $offset . ' to ' . $this->processed . ' (' . floor($this->processed / $this->total * 100) . '%).'); }); $this->write('info', '=== [/JOBS] ==='); }