Description
I just ran into this issue where we wanted to use scoped keys on our Meilisearch instance - only allowing keys to modify the index allocated to the site. But we run into a problem as on deploy we run php please search:update --all which according to this code:
https://github.com/statamic-rad-pack/meilisearch/blob/main/src/Meilisearch/Index.php#L88-L96
deletes and recreates the index before re-indexing everything. This is a problem because:
- All your custom index settings get wiped if you don't have them in Statamic's search config itself
- Deleting the index causes the scoped keys to not be associated to anything
- You can't delete/create indexes without having Master key level permissions on each site which is a security risk we'd like to avoid.
The solution is already laid out in Scout:
https://github.com/laravel/scout/blob/11.x/src/Engines/MeilisearchEngine.php#L55-L106
https://github.com/laravel/scout/blob/11.x/src/Engines/MeilisearchEngine.php#L373-L378
When they perform an update they only push content - they don't delete it. And if they do flush the index they just call deleteAllDocuments on the index instead of deleting + creating.
Steps to reproduce
- Set up a Meilisearch instance with a scoped key to an index
- Set up Statamic with the Meilisearch instance using the scoped key
- Run
php please search:update --all - it will error due to the scoped key not having permissions to create indexes
Environment
Environment
Application Name: Website
Laravel Version: 11.47.0
PHP Version: 8.4.19
Composer Version: 2.9.5
Environment: local
Debug Mode: ENABLED
URL: website.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: redis
Session: file
Livewire
Livewire: v3.7.3
Statamic
Addons: 1
Sites: 1
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.70.0 PRO
Statamic Addons
statamic-rad-pack/meilisearch: 3.4.0
Description
I just ran into this issue where we wanted to use scoped keys on our Meilisearch instance - only allowing keys to modify the index allocated to the site. But we run into a problem as on deploy we run
php please search:update --allwhich according to this code:https://github.com/statamic-rad-pack/meilisearch/blob/main/src/Meilisearch/Index.php#L88-L96
deletes and recreates the index before re-indexing everything. This is a problem because:
The solution is already laid out in Scout:
https://github.com/laravel/scout/blob/11.x/src/Engines/MeilisearchEngine.php#L55-L106
https://github.com/laravel/scout/blob/11.x/src/Engines/MeilisearchEngine.php#L373-L378
When they perform an update they only push content - they don't delete it. And if they do flush the index they just call
deleteAllDocumentson the index instead of deleting + creating.Steps to reproduce
php please search:update --all- it will error due to the scoped key not having permissions to create indexesEnvironment
Environment
Application Name: Website
Laravel Version: 11.47.0
PHP Version: 8.4.19
Composer Version: 2.9.5
Environment: local
Debug Mode: ENABLED
URL: website.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: redis
Session: file
Livewire
Livewire: v3.7.3
Statamic
Addons: 1
Sites: 1
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.70.0 PRO
Statamic Addons
statamic-rad-pack/meilisearch: 3.4.0