laravel 使用elasticsearch

来源:互联网 发布:风暴大陆神器进阶数据 编辑:程序博客网 时间:2024/06/08 18:52
首先你得要安装elasticsearch:https://my.oschina.net/frylan/blog/639980  ,
                                              http://blog.csdn.net/sinat_28224453/article/details/51516061


然后是使用laravel的elasticsearch包:
安装教程:https://github.com/elasticquent/Elasticquent#how-elasticquent-works

用法(使用前必须创建对应的索引):
首先要创建索引才能用,可以创建create操作时加入如下:
$data->addToIndex();   //为其添加elasticsearch索引

然后在更新物品时加入如下:
$info->updateIndex();

然后在删除是加入如下:
$info->removeFromIndex();   //elasticsearch移除索引

这样就能很好的维护在elasticsearch的索引了,可以用以下执行搜索:
//使用elasticsearch搜索
$data = Good::searchByQuery(array('match' => array('goods_name' => $keyword)));


参考文档:https://es.xiaoleilu.com/050_Search/15_Pagination.html
参考api:/vendor/elasticquent/elasticquent/src/ElasticquentTrait.php  (查看源码可可看到更详细api)
参考工具:http://localhost:9200/_plugin/head/ 
(使用前需plugin install mobz/elasticsearch-head安装(具体见elasticsearch安装教程))



1 1