Explorer icon indicating copy to clipboard operation
Explorer copied to clipboard

Batch indexing model with condition

Open dyanakiev opened this issue 1 year ago • 1 comments

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.

dyanakiev avatar Dec 12 '23 09:12 dyanakiev

The update command is very straightforward, if I were you I would just copy it and modify to my needs 😄

Jeroen-G avatar Dec 12 '23 20:12 Jeroen-G