Search code examples
laravellaravel-5algolialaravel-scout

Scout Algolia doesn't delete when objectId is not Primary key


When I import my model to Algolia I change the ObjectId to the value of another field. But it seems when I call delete() on my object it doesn't remove it from Algolia. To be more clear here is an example:

User{ id, email name }

Algolia User {objectId :email,name}

is there a way to solve this issue? Does scout have a function to overwrite the original delete function similiar to toSearchableArray?

EDIT: I have requested this feature on Scout GitHub for anyone interested


Solution

  • I ended up using Algolia SDK to manually delete it.

        $client = new \AlgoliaSearch\Client(env('ALGOLIA_APP_ID'), env('ALGOLIA_SECRET'));
        $index = $client->initIndex('index_name');
        $index->deleteObject($model->email);