如何使用Laravel 5在elasticsearch中进行分页

时间:2016-03-10 05:12:05

标签: laravel elasticsearch laravel-5 pagination

我是弹性搜索的新手,我想在其中使用分页。

我正在使用和尺寸。我现在共有10条记录,我从0到5和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);

现在我的查询在哪里给出分页链接?

1 个答案:

答案 0 :(得分:0)

在存储库中

        $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;

在控制器中我设置$ per_page和$

$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());

现在在视图中使用渲染{{!! $ admin_exceptions-> render()!!}}