mirocow / yii2-elasticsearch
基于官方 Elasticsearch PHP 库的 Yii2 Elasticsearch 客户端
1.0.22
2019-10-20 00:54 UTC
Requires
- php: >=5.4.0
- elasticsearch/elasticsearch: ^5.0
- yiisoft/yii2: >=2.0
README
文档支持英文和俄语。基于 https://github.com/elastic/elasticsearch
蜂蜜模块
安装
$ composer require --prefer-dist mirocow/yii2-elasticsearch
Elasticsearch 5.6.x
$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - $ sudo apt-get install apt-transport-https $ echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list $ sudo apt-get update && sudo apt-get install elasticsearch $ composer require --prefer-dist mirocow/yii2-elasticsearch
配置
- 创建一个实现
common\modules\elasticsearch\contracts\Index
接口的类。 - 将其添加到
common/config/main.php
中的模块配置。 - 开始索引
return [ 'modules' => [ // elasticsearch common\modules\elasticsearch\Module::MODULE_NAME => [ 'class' => common\modules\elasticsearch\Module::class, 'indexes' => [ common\repositories\indexes\ProductsSearchIndex::class ] ], ], 'bootstrap' => [ mirocow\elasticsearch\Bootstrap::class, ] ];
创建索引
创建空索引
$ php yii elasticsearch/index/create index_name
用所有文档填充索引
$ php yii elasticsearch/index/populate index_name
销毁索引及其所有数据
$ php yii elasticsearch/index/destroy index_name
删除所有现有索引,重新创建所有索引并重新索引所有索引中的文档
$ php yii elasticsearch/index/rebuild
调试
$ export PHP_IDE_CONFIG="serverName=www.site.loc" && export XDEBUG_CONFIG="remote_host=192.168.1.6 idekey=xdebug" && php7.0 ./yii elasticsearch/index/create products_search
查询
<?php /** @var QueryBuilder $query */ $query = new QueryBuilder; $query = $query ->add(QueryHelper::bool($filter, $must, $should, $must_not)) ->aggregations($aggregations) ->withSource('attributes');