Explorer
Explorer copied to clipboard
Batch indexing model with condition
Hello,
Is there a way currently to batch index multiple records similar to the elastic:update command, but with where condition?
I create many records in database and then i have to foreach the records and save them to get them in elasticsearch which is very slow.
Something like Model::index()->where('agency_id', '=', 1)
, this internaly should handle the indexing and batching, is there a way to achieve this? I dont understand why elastic:update is faster if its doing similar to foreaching the models.
This is very slow:
$agency->clients()->chunk(1000, function ($clients) {
foreach ($clients as $client) {
$client->touch();
}
});
Running elastic:update index_name is way faster.
The update command is very straightforward, if I were you I would just copy it and modify to my needs 😄