novius / laravel-scout-elasticsearch-driver
Elasticsearch Driver for Laravel Scout
Installs: 8 956
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 4
Forks: 2
Open Issues: 2
Requires
- php: ^8.2
- elasticsearch/elasticsearch: ^7.17
- laravel/framework: ^10.0
- laravel/scout: ^10.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.14
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^9.0
README
This package is an adaptation of babenkoivan/scout-elasticsearch-driver to get working with Elasticsearch >= 7.0.0
This package version was created to be compatible with Elasticsearch "Removal of mapping types" introduced in Elasticsearch >= 7.0.0
Features added
-
Model's type is now saved in
type
field by default according to Elasticsearch recommendations -
After a model search, an attribute
_score
will be hydrated on your result Model.
Example :
$results = MyModel::search('keywords')->get(); foreach ($results as $result) { // Score is now available in : $result->_score }
- Logs : you can now use Laravel loggers to log ElasticSearch's requests
To enable logs you have to set SCOUT_ELASTIC_LOG_ENABLED
to true
and specify which log's channel(s) to use.
Example :
config/logging.php
<?php return [ ... 'channels' => [ ... 'es' => [ 'driver' => 'daily', 'path' => storage_path('logs/es.log'), 'level' => 'debug', 'days' => 5, ], ], ];
elastic:reindex
a new command to build and populate a new index with 0 downtime ;
config/scout_elastic.php
<?php return [ 'client' => [ 'hosts' => [ env('SCOUT_ELASTIC_HOST', 'localhost:9200'), ], ], 'document_refresh' => env('SCOUT_ELASTIC_DOCUMENT_REFRESH'), 'searchable_models' => [], 'log_enabled' => env('SCOUT_ELASTIC_LOG_ENABLED', false), 'log_channels' => [], ];
Features deleted from original package
elastic:update-mapping
command ;elastic:migrate
command ;elastic:update
command ;- Mapping of models : replaced by
getDefaultMapping()
of index configurator ; - Single indexer ;
Requirements
- PHP >= 7.4
- Laravel Framework >= 7.25
- Elasticsearch >= 7.0.0
For Laravel > 6 and < 7.25 you can install 2.x version.
Installation
composer require novius/laravel-scout-elasticsearch-driver:dev-master
Configuration
To configure the package you need to publish settings first:
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
php artisan vendor:publish --provider="Novius\ScoutElastic\ScoutElasticServiceProvider"
Then, set the driver setting to elastic
in the config/scout.php
file and configure the driver itself in the config/scout_elastic.php
file.
The available options are:
Note, that if you use the bulk document indexing you'll probably want to change the chunk size, you can do that in the config/scout.php
file.
Usage
Please read the original package documentation.
Lint
Run php-cs with:
composer run-script lint
Contributing
Contributions are welcome! Leave an issue on Github, or create a Pull Request.
Licence
This package is under MIT Licence.