Laravel Scout (Meilisearch) - Says imported data, but doesn't

Viewed 2011

I've installed and configured meilisearch + Laravel Scout package.

My Model:

class Post extends Model
{
    use Searchable;
}

When I run php artisan scout:import 'App\Models\Post' it returns:

Imported [App\Models\Post] models up to ID: 5
All [App\Models\Post] records have been imported.

But when I check the index, it's empty. Why?

The index is being created, but the data doesn't get imported.

The same configuration of meilisearch and Scout package, works for some other models.

3 Answers

I've just run into this issue myself and came across your question. I don't suppose you're specifying what should be stored in the index are you?

I.e. in your model, have you created a toSearchableArray method like the below...

public function toSearchableArray(): array
{
    return [
        'name' => $this->name,
    ];
}

If you have, it turns out that your toSearchableArray method must also return the primary key within the array, otherwise the record does not get indexed.

public function toSearchableArray(): array
{
    return [
        'id'   => $this->getKey(), // this *must* be defined
        'name' => $this->name,
    ];
}

You can try to set:

SCOUT_QUEUE=false

To check that there is no issue with your queues and run the import again.

For index you can try:

php artisan scout:index posts

There is no other issue with your queues and run the import again.

If you have SCOUT_QUEUE=true then please, start your queue using php artisan queue:work --daemon and your data will be start importing.

Related