New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

thaoha/eloquent-search

Index Eloquent models to Elasticsearch
532

Larablocks Analysis

thaoha/eloquent-search works with any PHP project: the latest release (v1.0.3, Jan 23, 2017) doesn't depend on Laravel.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • No release in the last 12 months (last: Jan 23, 2017)
  • 0 downloads a month (needs 10,000)
  • 0 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Jan 23, 2017.
  • No releases in the last 12 months.
  • First released: Dec 20, 2016.
  • 1 open issue on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 2, 2026.

Install
composer require thaoha/eloquent-search
Latest Version:v1.0.3
PHP:>=5.5.9
License:MIT
Last Updated:Jan 23, 2017
Links: GitHub  ·  Packagist
Maintainer: thaoha

Latest Stable Version License

Index Eloquent models to Elasticsearch. Eloquent-search use Official low-level client for Elasticsearch. You should read more about Elasticsearch at https://www.elastic.co to get basic knowledge.

Installation via Composer

The recommended method to install eloquent-search is through Composer.

composer require thaoha/eloquent-search

Once you've run a composer update, you need to register Laravel service provider, in your config/app.php:

'providers' => [
    ...
    EloquentEs\EloquentEsServiceProvider::class,
],

Or with Lumen, you need add to bootstrap/app.php:

$app->register(EloquentEs\EloquentEsServiceProvider::class);

And now you can add ElasticModelTrait to any Eloquent model you want to index to Elasticsearch:

use EloquentEs\Supports\ElasticModelTrait;

/**
 * Class Company
 * @package App\Models
 */
class Company extends Model
{
    use ElasticModelTrait;
    ...
}

Config

Laravel 5:

$ php artisan vendor:publish --provider="EloquentEs\EloquentEsServiceProvider"

Or you can copy config.php file to your config folder and change the filename to elastic.php. With Lumen you need add new config file to bootstrap/app:

$app->configure('elastic');

Index

Create index to store your data first. Use esCreateIndex() function from you model class:

App\Models\Company::esCreateIndex();

esCreateIndex() function use property $esIndexMapping in Company model to set mapping settings. Elastic will auto detect if $esIndexMapping empty:

/**
     * Index mapping
     *
     * @var array
     */
    private $esIndexMapping = [
        'id'            => ['type' => 'long'],
        'name'          => ['type' => 'string'],
        'company'       => ['type' => 'string']
    ];

If you want to update mapping settings you can use (use esReset() function when conflict error):

App\Models\Company::esPutMapping();

Delete index:

App\Models\Company::esDeleteIndex();

Reset index. Just use this function (this function will delete all your index include your data and create new one with mapping settings):

App\Models\Company::esReset();

Get and Index model

With each model object already use ElasticModelTrait you can index to Elasticsearch with esIndex() function:

$company = App\Models\Company::find(1);
$company->esIndex();

With default it will be use $company->toArray() to get data. Very easy to override with esSerialize() function:

/**
     * Get eloquent model data
     *
     * @return array
     */
    public function esSerialize()
    {
        $data = $this->toArray();
        $data['user_id'] = 1;
        
        return $data;
    }

Delete model

$company = App\Models\Company::find(1);
$company->esDelete();

Update model

$company = App\Models\Company::find(1);
$company->esReindex();

a Model or a Collection you can do with same way.

$params = [
    'match' => ['name' => 'keyword']
];
$hits = App\Models\Company::esSearch($params);

You should read more at https://www.elastic.co/ to build you params search

Alternatives to thaoha/eloquent-search

pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

664,871 2
jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

813,230 399
novius/laravel-scout-elasticsearch-driver

Elasticsearch Driver for Laravel Scout

10,331 5
sleimanx2/plastic

Plastic is an Elasticsearch ODM and mapper for Laravel. It renders the developer...

142,811 506

Version History

Version Released PHP License
v1.0.3 >=5.5.9 MIT
v1.0.2 >=5.5.9 MIT
v1.0.1 >=5.5.9 MIT
v1.0 >=5.5.9 MIT