/** * Execute the console command. * * @return mixed */ public function handle() { $self = $this; if ($this->option('reset')) { if ($this->elastic->indices()->exists(['index' => 'tenders'])) { $this->elastic->indices()->delete(['index' => 'tenders']); $this->info('Удален индекс tenders'); } $this->elastic->indices()->create(['index' => 'tenders']); $this->info('Создан индекс tenders'); $this->elastic->indices()->putMapping(['index' => 'tenders', 'type' => 'contract', 'body' => ['properties' => ['id' => ['type' => 'integer'], 'region_id' => ['type' => 'integer'], 'name' => ['type' => 'string', 'fields' => ['russian' => ['type' => 'string', 'analyzer' => 'russian']]], 'organization' => ['type' => 'string', 'fields' => ['russian' => ['type' => 'string', 'analyzer' => 'russian']]]]]]); Contract::chunk(1000, function ($contracts) { foreach ($contracts as $contract) { $this->put($contract); } }); } else { $result = $this->elastic->search(['index' => 'tenders', 'type' => 'contract', 'size' => 1, 'body' => ['query' => ['match_all' => []], 'sort' => ['id' => 'desc']]]); $last_id = $result['hits']['hits'][0]['_id']; Contract::where('id', '>', $last_id)->chunk(1000, function ($contracts) { foreach ($contracts as $contract) { $this->put($contract); } }); } }