简体   繁体   中英

Limit query with elasticsearch using Yii2

I'm using elasticsearch with Active Records in Yii2.

    static function getPosts()
    {
        return Post::find()
            ->orderBy('ID desc')
            ->all();
    }

The method find () works fine, but if I add the method limit(), it stops working.

    static function getPosts()
    {
        return Post::find()
            ->orderBy('ID desc')
            ->limit(20)
            ->all();
    }

How I can use in a query limit with Active Records, Elasticsearch and Yii2?

Regards.

Noup.

Active Records is not compatible whit limit() function.

You have to use query() function for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM