dev-master
9999999-dev https://github.com/BittenByte/laravel-scout-elasticsearchElasticSearch Custom Engine for Laravel Scout
MIT
The Requires
laravel elasticsearch engine scout
ElasticSearch Custom Engine for Laravel Scout
An ElasticSearch Custom Engine implementation for Laravel Scout (3.*), (*1)
IMPORTANT this is still an experimental package!!!, (*2)
Install the package via composer:, (*3)
composer require bittenbyte/laravel-scout-elasticsearch
Add the service provider to the providers section in the config/app.php (of course you need Scout too), (*4)
... BittenByte\ScoutElasticsearchEngine\ScoutElasticsearchEngineServiceProvider::class, ...
In the config/scout.php set the driver properly and add a key as per below:, (*5)
... 'driver' => 'elasticsearch', ... 'elasticsearch' => [ 'config' => [ 'hosts' => array_map('trim', explode(',', env('ELASTICSEARCH_HOSTS', 'localhost'))), ], //default searchable fields per index 'fields' => [ 'users_index' => [ 'name', 'email', 'role', 'slug', ], ], 'indices' => [ //set your OPTIONAL index specific settings and mappings 'users_index' => [ 'settings' => [ 'number_of_shards' => 3, 'number_of_replicas' => 2 ], 'mappings' => [ 'authenticable' => [ '_source' => [ 'enabled' => true, ], 'properties' => [ 'name' => [ 'type' => 'string', 'index' => 'not_analyzed', ], 'slug' => [ 'type' => 'string', 'index' => 'not_analyzed', ], 'role' => [ 'type' => 'string', 'index' => 'not_analyzed', ], 'email' => [ 'type' => 'string', 'index' => 'not_analyzed', ], ], ], ], ], ], ],
Follow this documentation below and the official docs for scout, (*6)
Advanced/Custom query builder, (*7)
Not to forget from Scout docs, (*8)
indexation is automaticaly hooked to Eloquent create, update and (soft)delete operations, (*9)
Also is possible to index/remove from index manually, (*10)
// Updating via Eloquent query... App\Order::where('price', '>', 100)->searchable(); // You may also update via relationships... $user->orders()->searchable(); // You may also update via collections... $orders->searchable();
// Removing via Eloquent query... App\Order::where('price', '>', 100)->unsearchable(); // You may also remove via relationships... $user->orders()->unsearchable(); // You may also remove via collections... $orders->unsearchable();
This is useful specially when doing batch operations, (*11)
App\Order::withoutSyncingToSearch(function () { // Perform model actions... });
$orders = App\Order::search('Star Trek')->get();
$orders = App\Order::search('Star Trek')->where('user_id', 1)->get();
$orders = App\Order::search('Star Trek')->paginate();
ElasticSearch Custom Engine for Laravel Scout
MIT
laravel elasticsearch engine scout