整合搜索到ES

1、elasticsearch的安装就跳过了,搜轮子:https://packagist.org/?query=scout%20%20elastic
步骤参考:https://github.com/babenkoivan/scout-elasticsearch-driver#search-rules

2、记录下其他细节或坑

  • IndexConfigurator的$name定义index名,model的searchableAs()定义type名;

  • 关于create index时的settings和mappings

参考: https://www.elastic.co/guide/en/elasticsearch/guide/current/_creating_an_index.html
https://www.elastic.co/guide/en/elasticsearch/reference/6.7/removal-of-types.html
该库也是将settings放到IndexConfigurator中的,mapping放到各自model中的;

  • 存到ES中的字段由model中的toSearchableArray()决定

  • 查找字段和查找规则由model的$searchRules中的SearchRule决定

参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-highlighting

  • 向model中添加数据,index中没有立刻生成相应记录

是因为我把SCOUT_ELASTIC_DOCUMENT_REFRESH设成了false,改为true即可

  • 已有model导入历史数据

由于文档说config/scout.php中queue配置成true,性能会提高,所以果断.env中设成true,然后参考https://laravel.com/docs/5.8/scout#indexing,执行

php artisan scout:import "App\Services\Subject\Models\Subject"

然后刷新:http://127.0.0.1:9200/_cat/indices?v,一直没见docs.count变多,所以只好先把queue设为false,再次执行上面的命令即可。

  • 关于scout使用queue,自定义queue

参考:https://github.com/laravel/scout/issues/302

keyword:laravel | elasticsearch | ES | 搜索 | scout

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容