Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch indexing model with condition #226

Open
dyanakiev opened this issue Dec 12, 2023 · 1 comment
Open

Batch indexing model with condition #226

dyanakiev opened this issue Dec 12, 2023 · 1 comment

Comments

@dyanakiev
Copy link

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.

@Jeroen-G
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants