首页 > Yii2-elasticsearch 怎么用啊?

Yii2-elasticsearch 怎么用啊?

想把自己的博客用上 ElasticSearch 搜索,用的是 Yii2-elasticsearch 扩展

搞了半天不会用,没搞明白 elasticsearch 是个怎么回事,是要把 Mysql 中的数据弄到 ES 中去吗?

难道每次都要到msql中去把数据找出来,再一个一个赋值给 ES 吗?

$posts = Post::find()->all();

$postElastic = new PostElastic();
$postElastic->attributes = ['name' => $postElastic[0]->name];

要像上面这样嘛?那也太蛋疼了吧

但是直接 Contents::find()->all() 查出来的也没有数据,

class Contents extends \yii\elasticsearch\ActiveRecord
{    
    public function attributes()
    {
        return ['id', 'title', 'slug', 'created_at', 'text', 'type', 'status'];
    }

}
【热门文章】
【热门文章】