wehaa / laravel-scout-elasticsearch
Elasticsearch Driver for Laravel Scout
Installs: 1 309
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- php: >=7.1
- elasticsearch/elasticsearch: ^6.0
- laravel/scout: ^8.0|^9.0
Requires (Dev)
- mockery/mockery: ^1.2
- phpunit/phpunit: ~6.0
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"