'Laravel Scout (Meilisearch) - Says imported data, but doesn't
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.
Solution 1:[1]
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,
];
}
Solution 2:[2]
You can try to set:
SCOUT_QUEUE=false
To check that there is no issue with your queues and run the import again.
Solution 3:[3]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | rccode |
Solution 3 | Rajesh Patadiya |