Laravel 4.2+ wrapper for ElasticSearch

0.2.0 2015-04-10 13:50 UTC

This package is not auto-updated.

Last update: 2020-06-26 18:15:23 UTC



I need to improve search. Currently using mongob, 2dspheres etc.

Bring on Elasticsearch. Basically just a wrapper for the offical client.

Afternoon hack
  • Trying to put togeter a nice package so we can use ElasticSearch easily
  • Should play well with league/fractal
  • Should play well with illuminate/collections
  • Should play well with fractal/item
  • Should play well with fractal/resources
  • etc..

Install via Composer

require : {
	"almeida/laravel-elasticsearch" : "dev-master"

Step 1

Extend the abstract ElasticDocument so you get some easy CRUD.

Let's assume we are working with movies.

 * Acme\Search\MovieDocument
class MovieDocument extends \Almeida\LaravelElasticSearch\ElasticDocumentAbstract
	protected $index = 'movie_cluster';

	protected $type = 'movies';

	public function setId($movie) {
		return $movie->id;


Creating / Updating an index

Create an index.

Assuming you have already a working fractal/transformer

	$options = [];
	$options['transformer'] = 'Acme\MovieTransformer';

	$document = new \Acme\Search\MovieDocument($options);
	// or $document->create();
	// or $document->update();

	// OR
	$document = new \Acme\Search\MovieDocument();

Deleting an index (@todo)

Deleting an index.

	$document = new \Acme\Search\MovieDocument();

Indexing en masse in the Console

	$n = 0;

	Movie::chunk(100, function($movies) use(&$n) {

		foreach ($movies as $i => $movie) {

			$document = new \Acme\Search\MovieDocument();

			$this->info("Indexed : {$movie->title}");


	$this->info("Indexed [{$n}] movies");

Searching (WIP)

Promise to work on it over the next few days.

	$movieTitle = 'Scarface';


  • think about this more

  • Move search, stats, and aggerates to Traits so we only use them on applicable documents


Deving locally on OSX i couldnt get the client to connect to elasticsearch even though i could access it in the browser at http://localhost:9200

This fixed it for now...

The correct way to access is actually through,

Will work it out when i sort out nicer config etc.

Required reading


How is it calculated ?

Monitoring elasticsearch using Marvel (dev)

Thanks for the notes

I accept bitcoin tips. [18tEqEUnyJaqvKh3CCNAAai9seztLb3Tw9].

They should too! Come on its going to be a thing.