> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Import into Algolia

> How to import data using Laravel Scout with Algolia Scout Extended.

export const Records = () => <Tooltip tip="A record is a searchable object in an Algolia index. Each record consists of named attributes." cta="Algolia records" href="/doc/guides/sending-and-managing-data/prepare-your-data#algolia-records">
    records
  </Tooltip>;

export const Index = () => <Tooltip tip="An Algolia index is a searchable dataset that consists of records and configuration settings. These settings define how the records are searched and ranked.">
    index
  </Tooltip>;

When setting up Scout Extended, you probably have existing data that you would like to import.
Use the `scout:import` Artisan command to import the data:

```sh Command line icon=square-terminal theme={"system"}
php artisan scout:import
```

The `searchable` classes are automatically detected,
but feel free to specify the `searchable` class to import:

```sh Command line icon=square-terminal theme={"system"}
php artisan scout:import "App\Article"
```

Foe more information about importing data in a production environment, see [Zero downtime re-imports](/doc/framework-integration/laravel/production/zero-downtime-reimports).

## Indexing issues

You may encounter indexing problems if you have cached configuration files, queue settings, connection errors, or record sizes.

### Cached configuration files

If `php 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:

```sh Command line icon=square-terminal theme={"system"}
php artisan cache:clear
php artisan route:clear
php artisan config:cache
composer dumpautoload
```

### Queue settings

If `queue` 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](https://dashboard.algolia.com/account/api-keys/all).
* Check for recent changes in your code.
* Check the status of your data center provider.

<Info>
  If you're using Firebase, you can only access Algolia from a paid Firebase tier.
</Info>

If you can't solve the problem yourself, contact the [Algolia support](https://support.algolia.com/hc/en-us/requests/new) team and provide them with the following information:

* The name of your [framework integration](/doc/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](https://wikipedia.org/wiki/Coordinated_Universal_Time) of the event
* If you can't connect to the Algolia API from your browser, send the output from [community.algolia.com/diag/](https://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):

  ```sh Command line icon=square-terminal theme={"system"}
  curl -sL https://algolia.com/downloads/diag.sh > ./diag.sh && sudo ./diag.sh ALGOLIA_APPLICATION_ID
  ```

  <Check>Replace `ALGOLIA_APPLICATION_ID` with *your* Algolia application ID.</Check>

### 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](https://support.algolia.com/hc/en-us/articles/4406981897617-Is-there-a-size-limit-for-my-index-records-).
Reduce the size of your records and try again.

## Flushing and clearing

The `scout:flush` Artisan command is the easiest way to flush the data from Algolia's index:

```sh Command line icon=square-terminal theme={"system"}
php artisan scout:flush
```

## 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 your `searchable` class as usual. For example, in a controller you may have:

```php PHP icon=code theme={"system"}
class ArticleController extends Controller
{
    /**
     * Update the given article.
     *
     * @param  Request  $request
     * @param  string  $id
     * @return Response
     */
    public function update(Request $request, $id)
    {
        Article::find(request('id'));

        $article->title = request('title');

        /**
         *  Scout will automatically persist the
         *  changes to your Algolia search index.
         */
        $article->update();
    }
}
```

The data isn't synced when using [mass assignment](https://laravel.com/docs/eloquent#inserting-and-updating-models) methods,
since the `saved` and `updated` events aren't dispatched in that case:

```php PHP icon=code theme={"system"}
/**
 *  Here, Scout will NOT persist the
 *  changes to your Algolia search index.
 */
Article::where('id', request('id'))
    ->update(['title' => request('title')]);
```

### Conditional model sync

Sometimes you might want to sync a `searchable` 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 PHP icon=code theme={"system"}
class Article extends Model
{
    use Searchable;

    public function shouldBeSearchable()
    {
        return $this->isPublished();
    }
}
```

## Pause indexing

The Scout documentation shows a nice way to change a searchable model without triggering indexing calls [using a callback](https://laravel.com/docs/scout#pausing-indexing).

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 your `DatabaseSeeder` class:

```php PHP icon=code theme={"system"}
class DatabaseSeeder extends Seeder
{
    public function run()
    {
        Article::disableSearchSyncing();

        $this->call(ArticleSeeder::class);

        Article::all()->searchable();

        Article::enableSearchSyncing();
    }
}
```
