php - 使用Yii2使用Elasticsearch限制查询

标签 php activerecord elasticsearch yii2 limit

我在Yii2中将Elasticsearch与Active Records一起使用。

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

方法find()可以正常工作,但是如果我添加方法limit(),它将停止工作。

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

如何在Active Records,Elasticsearch和Yii2的查询限制中使用?

问候。

最佳答案

没事
Active Records与limit()函数不兼容。
您必须为此使用query()函数。

关于php - 使用Yii2使用Elasticsearch限制查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36413915/

相关文章:

php - 解析 REST API : Having the channel name, 我可以在实际发送到 Push 之前获取设备类型吗?

sql - 如何在单个查询中从 ActiveRecord 中的父项中选择唯一子项?

lucene - 我可以自定义 Elastic Search 以使用我自己的停用词列表吗?

php - 修改并重做 codeigniter 中的最后一个查询

ruby-on-rails - rails 4.1。 Heroku ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR: operator does not exist: numeric - character varying

ruby-on-rails - 如何在Rails中使用elasticsearch来搜索category.name?

java - 使用elasticsearch搜索最相似的字符串

php - SQL 加入和排除查询的问题

php - 创建 HTML(PHP 或 Jquery)的最佳实践?

php - 使用 Webmin 设置一个 cron 作业