1、你确保你的java环境有安装

laravel安装和配置搜索功能_elasticsearch

没有的话百度这个下载就可以了

laravel安装和配置搜索功能_laravel_02



然后你需要 这两个github的地址

elasticsearch    https://github.com/medcl/elasticsearch-rtf

scout   https://github.com/ErickTamayo/laravel-scout-elastic

和laravel 安装 scout 的 步骤  http://d.laravel-china.org/docs/5.4/scout  把这个三个页面打开


先下载elasticsearch 这个就是 下载一个压缩包、然后解压、启动(windows系统启动是进到bin里面的


elasticsearch.bat

)  github文档  https://github.com/medcl/elasticsearch-rtf



laravel安装和配置搜索功能_github_03

这个要一直开启这个进程 不然 搜索功能使用不了,这个就是为什么windows系统这么坑的一个原因

然后去到浏览器 访问  http://127.0.0.1:9200/

laravel安装和配置搜索功能_laravel_04







出现这个页面代表你安装成功了





我们是先操作 安装 scout  (这个步骤在 http://d.laravel-china.org/docs/5.4/scout 这个地址中 文档的介绍跟清楚)

composer require laravel/scout

laravel安装和配置搜索功能_github_05

安装好了之后 去到 ​​config/app.php​​ 配置文件的 ​​providers​​ 数组中 添加

Laravel\Scout\ScoutServiceProvider::class,


laravel安装和配置搜索功能_github_06


配置好了之后  我们就要把 它提上去 使用这个命令(文档的介绍跟清楚)

php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"


laravel安装和配置搜索功能_elasticsearch_07


然后你的config文件夹中会多了一个php文件   config/scout.php

laravel安装和配置搜索功能_github_08


好了  接下来我们安装 laravel-scout-elastic 打开这个页面(https://github.com/ErickTamayo/laravel-scout-elastic)

运行这个命令


composer require tamayo/laravel-scout-elastic


laravel安装和配置搜索功能_elasticsearch_09


laravel安装和配置搜索功能_laravel_10

添加到​​config/app.php​​ 配置文件的 ​​providers​​ 数组中 添加

laravel安装和配置搜索功能_github_11

安装就差不多了   现在开始修改配置文件  到 scout.php 里面的   在github的文档里面

Setting up Elasticsearch configuration

1、默认是algolia 修改成elasticsearch

'driver' => env('SCOUT_DRIVER', 'elasticsearch'),


laravel安装和配置搜索功能_github_12


2、增加一个驱动

laravel安装和配置搜索功能_github_13

索引名字自己定义