美文网首页
整合搜索到ES

整合搜索到ES

作者: 段义纬 | 来源:发表于2019-08-21 12:04 被阅读0次

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

相关文章

网友评论

      本文标题:整合搜索到ES

      本文链接:https://www.haomeiwen.com/subject/prlbsctx.html