wehaa/laravel-scout-elasticsearch

There is no license information available for the latest version (v0.5-alpha) of this package.

Elasticsearch Driver for Laravel Scout

v0.5-alpha 2024-08-08 18:46 UTC

This package is auto-updated.

Last update: 2024-11-08 19:21:27 UTC


README

This package makes use of the Elasticsearch driver for Laravel Scout.

Supporting Laravel and 5.7+

Installation

You can install the package via composer:

composer require wehaa/laravel-scout-elasticsearch

Setting up Elasticsearch configuration

This command will publish the scout.php configuration file to your config directory:

php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"

Then add the elasticsearch key in the array on config/scout.php file.

     'elasticsearch' => [
        /*
        |--------------------------------------------------------------------------
        | Custom Elasticsearch Client Configuration
        |--------------------------------------------------------------------------
        |
        | This array will be passed to the Elasticsearch client.
        | See configuration options here:
        |
        | http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/_configuration.html
        */
        
        'hosts' => [
            [
                'host' => env('ELASTICSEARCH_HOST', 'localhost'),
                'port' => env('ELASTICSEARCH_PORT', '9200'),
                'scheme' => '', // http or https
                'user' => '',
                'pass' => ''
            ]
        ],
        
        /**
         * The client will retry n times
         */
        'retries' => env('ELASTICSEARCH_RETRIES', 3),
        
        /*
        |--------------------------------------------------------------------------
        | Default Index Name
        |--------------------------------------------------------------------------
        |
        | This is the index name use for all models
        */
        
        'default_index' => 'wehaa',
     ]

.env file example:

SCOUT_DRIVER=elasticsearch
ELASTICSEARCH_HOST=http://127.0.0.1
ELASTICSEARCH_PORT=9200

Usage:

Now you can use Laravel Scout as described in the official documentation

Batch Import

If you are installing Scout into an existing project, you may already have database records you need to import into your search driver. Scout provides an import Artisan command that you may use to import all of your existing records into your search indexes:

php artisan scout:import "App\Post"

The flush command may be used to remove all of a model's records from your search indexes:

php artisan scout:flush "App\Post"