scout:import
Artisan command to import the data:
searchable
classes are automatically detected,
but feel free to specify the searchable
class to import:
Indexing issues
You may encounter indexing problems if you have cached configuration files, queue settings, connection errors, or record sizes.Cached configuration files
Ifphp artisan scout:import
doesn’t index your models, it’s possible that changes in your .env
or config/scout.php
file aren’t taking effect because they’re cached.
Clearing the cache may help:
Queue settings
Ifqueue
is set to true
in your config/scout.php
file, indexing jobs may be waiting to be processed by your queue worker.
To fix this issue, either run your queue worker and wait for it to process your jobs or set queue
to false
and index records synchronously.
Connection errors
Are you getting “Impossible to connect”, “Unable to connect”, or “Unreachable hosts” errors? First, make sure the issue isn’t at your end:- Ensure you’re using the correct application ID and API key. Find these credentials on your Algolia dashboard.
- Check for recent changes in your code.
- Check the status of your data center provider.
If you’re using Firebase, you can only access Algolia from a paid Firebase tier.
- The name of your framework integration (Laravel) and its version number
- A code snippet to reproduce the issue
- Error message or stack trace (if applicable)
- The name of the Algolia index that’s causing problems
- The exact UTC time of the event
- If you can’t connect to the Algolia API from your browser, send the output from community.algolia.com/diag/.
-
If you can’t connect to the Algolia API from your servers, send the output from the following command (run on any affected server):
Replace
ALGOLIA_APPLICATION_ID
with your Algolia application ID.
Record size
Any “Record at the position XX objectID=XX is too big” errors during indexing are because you’ve exceeded the size limit for records. Reduce the size of your records and try again.Flushing and clearing
Thescout:flush
Artisan command is the easiest way to flush the data from Algolia’s index:
Keep data in sync
Every time you save or update a model, Laravel emits an event. Scout listens for those events, informing your app to make an HTTP call to Algolia to update its index. You don’t have to do anything else, you can use yoursearchable
class as usual. For example, in a controller you may have:
PHP
saved
and updated
events aren’t dispatched in that case:
PHP
Conditional model sync
Sometimes you might want to sync asearchable
class just when something else is true. To do this, you can define a shouldBeSearchable
method on your searchable
class.
Scout Extended syncs your model if this method returns true
.
PHP
Pause indexing
The Scout documentation shows a nice way to change a searchable model without triggering indexing calls using a callback. You can also use a static method to turn off syncing. This is useful if you’re performing lots of SQL queries to change content. Once complete, you can sync the changes manually. For example, in yourDatabaseSeeder
class:
PHP