Laravel 5 - elasticsearch with pagination example

By Hardik Savani | June 25, 2016 | Category : Laravel Elasticsearch

If you haven't install elasticsearch and you don't know how to install elasticsearch in laravel then you have to see first bellow link, in this link you can set up elasticsearch from scratch like install package, use with laravel model etc. :

How to use elasticsearch from scratch in laravel 5?.

After finish step of above link, we can make elasticsearch with pagination view using laravel pagination eloquent. after impletement this example we could find layout like as bellow link.


Ok, we have to just few changes and we can make pagination in our laravel application. so first open ItemSearchController.php controller and replace index method this way.




* Display a listing of the resource.


* @return \Illuminate\Http\Response


public function index(Request $request)



$page = $request->input('page', 1);

$paginate = 3;

$items = Item::searchByQuery(['match' => ['title' => $request->input('search')]], null, null, $paginate, $page);

$offSet = ($page * $paginate) - $paginate;

$itemsForCurrentPage = $items->toArray();

$items = new \Illuminate\Pagination\LengthAwarePaginator($itemsForCurrentPage, $items->totalHits(), $paginate, $page);



return view('ItemSearch',compact('items'));



Ok, at last we have to just render pagination view using laravel pagination eloquent in blade file. so open ItemSearch.blade.php file and change this:



<div class="col-lg-12">


@foreach($items as $key => $value)

<h3 class="text-danger">{{ $value['title'] }}</h3>

<p>{{ $value['description'] }}</p>


{!! $items->appends(Input::all())->render() !!}




Try this one......

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: