我是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/