wehaa / laravel-scout-elasticsearch
此包最新版本(v0.5-alpha)没有可用的许可证信息。
Laravel Scout 的 Elasticsearch 驱动程序
v0.5-alpha
2024-08-08 18:46 UTC
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-09-08 19:01:25 UTC
README
此包使用了Elasticsearch驱动程序,用于Laravel Scout。
支持Laravel 5.7及以上版本
安装
您可以通过composer安装此包
composer require wehaa/laravel-scout-elasticsearch
设置Elasticsearch配置
此命令将发布scout.php配置文件到您的配置目录
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
然后在config/scout.php文件中的数组中添加elasticsearch
键。
'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文件示例
SCOUT_DRIVER=elasticsearch ELASTICSEARCH_HOST=http://127.0.0.1 ELASTICSEARCH_PORT=9200
用法
现在您可以使用Laravel Scout,如官方文档所述
批量导入
如果您正在将Scout安装到现有项目中,您可能已经有一些需要导入到搜索驱动程序中的数据库记录。Scout提供了一个Artisan命令,您可以使用它将所有现有记录导入到搜索索引中
php artisan scout:import "App\Post"
flush命令可用于从搜索索引中删除一个模型的所有记录
php artisan scout:flush "App\Post"