PHPackages                             thaoha/eloquent-search - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. thaoha/eloquent-search

ActiveLibrary[Database &amp; ORM](/categories/database)

thaoha/eloquent-search
======================

Index Eloquent models to Elasticsearch

v1.0.3(9y ago)0532MITPHP &gt;=5.5.9

Since Dec 20Compare

[ Source](https://github.com/thaoha/eloquent-search)[ Packagist](https://packagist.org/packages/thaoha/eloquent-search)[ Docs](https://github.com/thaoha/eloquent-search)[ RSS](/packages/thaoha-eloquent-search/feed)WikiDiscussions Synced 2w ago

READMEChangelog (2)Dependencies (1)Versions (5)Used By (0)

eloquent-search
===============

[](#eloquent-search)

[![Latest Stable Version](https://camo.githubusercontent.com/6b5773672f4808c1bfefb2f937b48b6fd5bc77f562fa4d8216c692949d1127fb/68747470733a2f2f706f7365722e707567782e6f72672f7468616f68612f656c6f7175656e742d7365617263682f762f737461626c65)](https://packagist.org/packages/thaoha/eloquent-search)[![License](https://camo.githubusercontent.com/ffaf7c937cc7ce9f4716a0324eaf45e06051e1c7b58ba64dca8634a629cab3b3/68747470733a2f2f706f7365722e707567782e6f72672f7468616f68612f656c6f7175656e742d7365617263682f6c6963656e7365)](https://packagist.org/packages/thaoha/eloquent-search)

Index Eloquent models to Elasticsearch. Eloquent-search use [Official low-level client for Elasticsearch](https://github.com/elastic/elasticsearch-php). You should read more about Elasticsearch at  to get basic knowledge.

Installation via Composer
-------------------------

[](#installation-via-composer)

The recommended method to install `eloquent-search` is through [Composer](http://getcomposer.org).

```
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
------

[](#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
-----

[](#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
-------------------

[](#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
------------

[](#delete-model)

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

Update model
------------

[](#update-model)

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

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

Search
------

[](#search)

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

You should read more at  to build you params search

###  Health Score

27

—

LowBetter than 46% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity61

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Total

4

Last Release

3489d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5896457?v=4)[Thao Ha](/maintainers/thaoha)[@thaoha](https://github.com/thaoha)

---

Tags

searchlaravelelasticsearchlumeneloquentelastic

### Embed Badge

![Health badge](/badges/thaoha-eloquent-search/health.svg)

```
[![Health](https://phpackages.com/badges/thaoha-eloquent-search/health.svg)](https://phpackages.com/packages/thaoha-eloquent-search)
```

###  Alternatives

[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

399693.0k](/packages/jeroen-g-explorer)[sleimanx2/plastic

Plastic is an Elasticsearch ODM and mapper for Laravel. It renders the developer experience more enjoyable while using Elasticsearch by providing a fluent syntax for mapping , querying and storing eloquent models.

507142.4k1](/packages/sleimanx2-plastic)[matchory/elasticsearch

The missing elasticsearch ORM for Laravel!

3066.0k](/packages/matchory-elasticsearch)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
