laravel - 如何使用Laravel 5在Elasticsearch中分页

标签 laravel elasticsearch laravel-5 pagination

我是Elasticsearch的新手,我想在其中使用分页。

我正在使用from和size。我现在总共有10条记录,而我正在从0扩展到5。我得到5个结果。但是,如何给链接提供查看页面以及如何增加第二页的记录呢?

我的查询:

       $params = [
                'index' => 'my_index',
                'type' => 'product',
                'body' =>  [
                    "sort" =>[
                                ["default_product_low_price.sale_price" => ["order" => $sort]]
                            ],
                    "from" => 0, "size" =>5,
                    'query'=> $query,
                  ]
                ];
          $response = \Es::Search($params);

这是我的查询现在在哪里可以给出分页链接?

最佳答案

在仓库中

        $params['size'] = $per_page;
$params['from'] = $from;
$params['index'] = config('elastic.Admin_Logs');
$params['type'] = config('elastic.Admin_Type');
$params['body']['sort']['default_product_low_price.sale_price']['order'] = "desc";
$params['body']['query']['filtered']['filter']['bool']['must'][]['match_all'] = [];

$response = \Es::Search($params);
 $access = $response['hits'];
        return $access;

在 Controller 中,我设置了$ per_page和$ from
$per_page = $request->get('limit', 10);
    $from = ($request->get('page', 1) - 1) * $per_page;
    $access = $this->repository->Index($per_page, $from);

    $admin_exceptions = new LengthAwarePaginator(
            $access['hits'],
            $access['total'],
            $per_page,
            Paginator::resolveCurrentPage(),
            ['path' => Paginator::resolveCurrentPath()]);
 return view('adminexception.index', compact('admin_exceptions'))->withInput($request->all());

现在在 View {{!! $ admin_exceptions-> render()!!}}中使用render

关于laravel - 如何使用Laravel 5在Elasticsearch中分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35908087/

相关文章:

mysql - Eloquent where() 语句

elasticsearch - 在 Elastic Search 中获取聚合记录的 _id 字段

elasticsearch - logstash索引文本文件

postgresql - 如何在无法迁移表的情况下对 Laravel 应用程序进行单元测试,因为迁移是由另一个应用程序处理的

php - Connection.php 行 647 : SQLSTATE[42000]: Syntax error or access violation 中的 Laravel QueryException

laravel-5 - 如何在laravel 5中返回数组而不是对象

Laravel API resourceCollection 使用数组而不是模型

javascript - 更新slot vuejs中的数据

php - 如何在 Laravel 的 Eloquent ORM 中按数据透视表数据排序

docker - Elasticsearch docker 镜像 - 使用免费端口