安装

composer require hyperf-ext/scout

该组件自动依赖了 hyperf-ext/elasticsearch 组件来使用 Elasticsearch 客户端,请在本组件安装完成后发布此组件的配置。

Scout 安装完成后,使用 vendor:publish 命令来生成 Scout 配置文件。这个命令将在你的 config/autoload 目录下生成一个 scout.php 配置文件。

php bin/hyperf.php vendor:publish hyperf-ext/scout

最后,在你要做搜索的模型中添加 HyperfExt\Scout\Searchable Trait。这个 Trait 会自动注册一个模型观察者来保持模型和 Elasticsearch 的同步:

use Hyperf\Database\Model\Model;
use HyperfExt\Scout\Searchable;

class Post extends Model
{
    use Searchable;
}

建议

使用这个model插入,使用elasticSearch Client查询

索引

创建索引并更新映射

php bin/hyperf.php scout:index:create "App\Models\Post"

更新索引设置

php bin/hyperf.php scout:index:update "App\Models\Post"

删除索引

php bin/hyperf.php scout:index:drop "App\Models\Post"

更新映射

php bin/hyperf.php scout:mapping:update "App\Models\Post"
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐