1、laravel安装ElasticSearch
1、安装ElasticSearch(一定要安装7.*版本,推荐7.1,否则 tamayo/laravel-scout安装一直报错!)
composer require elasticsearch/elasticsearch=“^7.,1” --ignore-platform-reqs
2、安装laravel es驱动(最终使用的这个扩展,索引字段类型在创建mysql表配置好即可)
composer require tamayo/laravel-scout-elastic --ignore-platform-reqs
3、安装scout
composer require tamayo/laravel-scout-elastic --ignore-platform-reqs
scout配置 https://learnku.com/docs/laravel/8.x/scout/9422#e05dce
4、安装es索引引擎e matchish/laravel-scout-elasticsearch (先不用装此扩展,因为导入es太慢)
composer require matchish/laravel-scout-elasticsearch=“^4.0” --ignore-platform-reqs
配置: https://github.com/matchish/laravel-scout-elasticsearch
生成 Scout 配置文件 (config/scout.php)
php artisan vendor:publish --provider=“Laravel\Scout\ScoutServiceProvider”
5.指定 Scout 驱动
第一种:在.env 文件中指定(建议)
SCOUT_DRIVER=Matchish\ScoutElasticSearch\Engines\ElasticSearchEngine
ELASTICSEARCH_HOST=127.0.0.1:9200 //指定ip
第二种:在 config/scout.php 直接修改默认驱动
‘driver’ => env(‘SCOUT_DRIVER’, ‘Matchish\ScoutElasticSearch\Engines\ElasticSearchEngine’)
6.注册服务
修改config/app.php文件
‘providers’ => [
// Other Service Providers
\Matchish\ScoutElasticSearch\ElasticSearchServiceProvider::class
],
7.清除配置缓存
php artisan config:clear
php artisan vendor:publish --tag config
生成config/elasticsearch.php 文件文章来源:https://www.toymoban.com/news/detail-502056.html
配置索引文章来源地址https://www.toymoban.com/news/detail-502056.html
<?php return [ 'host' => env('ELASTICSEARCH_HOST','127.0.0.1'), 'indices' => [ 'mappings' => [ 'ai_title' => [ 'properties' => [ 'id' => [ 'type' => 'float', ], ], ], 'ai_methods' => [ 'properties' => [ 'factors' => [ 'type' => 'float', ], ], ], ], 'settings' => [ 'default' => [ 'number_of_shards' => 1, 'number_of_replicas' => 0, ], ], ], ];到了这里,关于laravel安装ElasticSearch的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!