PHPackages                             tamizh/laravel-es - 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. tamizh/laravel-es

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

tamizh/laravel-es
=================

v1.0.30(8y ago)2277[4 issues](https://github.com/rtamizh/laravel-es/issues)MITPHP

Since Apr 22Pushed 7y ago2 watchersCompare

[ Source](https://github.com/rtamizh/laravel-es)[ Packagist](https://packagist.org/packages/tamizh/laravel-es)[ RSS](/packages/tamizh-laravel-es/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (3)Versions (32)Used By (0)

laravel-es
==========

[](#laravel-es)

The basic orm package for elasticsearch (search and CRUD functionalities) - for elasticsearch 5.0 and lesser versions

Installation
============

[](#installation)

```
composer require tamizh/laravel-es

```

or add the following line in composer.json line

"tamizh/laravel-es" : "dev-master" and run `composer update`

Configuration
=============

[](#configuration)

Add the service provider to your config/app.php file:

```
'providers'     => [
    //...
    Tamizh\LaravelEs\ElasticsearchServiceProvider::class,
],

```

Add the facade to your config/app.php file:

```
'aliases' => [
    //...
    'Elasticsearch' => Tamizh\LaravelEs\Elasticsearch::class,
],

```

Publish config file using `php artisan vendor:publish`

Modifiy the config/elasticsearch.php.

Example

```
return [
  'hosts' => [
    env('ES_HOSTS', 'localhost:9200')
  ],
  'log_path' => 'storage/logs/',
];

```

Instead of extends the Model class in your models extend the Elasticsearch to use the following functions.

```
class Log extends Elasticsearch
{
  public $_index = 'logs*';
  public $_type = 'log';
}

```

Available Functions
===================

[](#available-functions)

1. match &amp; match\_phrase - Returns the results that matches the text

    ```
    Log::match('field', 'text')->get()
    Log::matchPhrase('field', 'hello world')->get()
    Log::matchPhrasePrefix('field', 'hello')->get()

    ```
2. boolMust, boolMustNot, boolShould, boolShouldNot - Boolean queries (Equal to AND and OR in mysql)

    ```
    Log::boolMust(function($query){
        $query->match('field', 'text');
    })->get()

    ```
3. terms - Return the result that matches terms array

    ```
    Log::terms('field', array)->get()

    ```
4. aggs - Aggregate the result (sub aggregation not yet supported)

    ```
    Log::aggs(function($query){
        $query->terms('field')->size(10)->minDocCount(10);
    }, 'top_logs')

    ```

    Multiple aggregation can be achieved by

    ```
    Log::aggs(function($query){
        $query->terms('field')->size(10)->minDocCount(10);
    }, 'top_logs')
    ->aggs(function($query){
        $query->sum('field')
    });

    ```

    Sub Aggregation can be achieved by

    ```
    Log::aggs(function($query){
        $query->terms('field')
            ->aggs(function($sub_query){
                $sub_query->sum('field');
            });
    }, 'top_logs')

    ```

    available functions a) terms b) cardinality c) max d) min e) sum\_bucket f) sum d) date\_histogram (with interval option \[default - month\]) e) avg
5. sort - Sort the query result

    ```
    Log::sort('field', 'desc')

    ```

    or

    ```
    Log::sort(function($query){
        $query->script('return doc['error'].value + doc['success'].value')
    })

    ```
6. scroll - Get the Iterator Object to scroll.

    ```
    $results = Log::match('field', 'text')->size(100)->scroll();
    foreach($results as $result){
        // logic goes here
    }

    ```
7. size - Size of the result collection

    ```
    Log::match('field', 'text')->size(100)->get()

    ```
8. highlight - To highlight the selected text

    ```
    Log::match('field', $text)->highlight('field')->get()

    ```
9. first - To get first model

    ```
    Log::match('field', $text)->first()

    ```
10. save - To save the current model to the ES

    ```
    $log = Log::match('field', $text)->first();
    $log->count = $log->count + 1;
    $log->save();

    ```
11. delete - To delete the current model from ES

    ```
    $log = Log::match('field', $text)->first();
    $log->delete();

    ```

    or

    ```
    Log::delete(1);

    ```
12. query\_string - query string function in ES

    ```
    $log = Log::queryString(function($query){
        $query->query('tech*')
            ->fields(['errors', 'content']);
    })->get();

    ```

    in bool functions

    ```
    Log::boolMust(function($query){
        $query->queryString(function($query){
            $query->query('tech*')
                ->fields(['errors', 'content']);
        })
    })->get();

    ```
13. exists - exists condition functionality

    ```
    $log = Log::exists('field')->get();

    ```
14. index - index document in ES

    ```
    Log::index(['key' => 'value', 'key1' => 'value1'], id);

    ```
15. update - update document in ES

    ```
    Log::update(['new_key' => 'new_value', 'old_key' => 'new_value'], id);

    ```
16. removeKey - remove unwanted key from ES

    ```
    Log::removeKey('unwanted_key', id);

    ```
17. script - script functionality

    ```
    Log::script("doc['errors'].value > 10")->get()

    ```
18. count - get count of documents for current result

    ```
    Log::script("doc['errors'].value > 10")->count()

    ```
19. range - get the result set between a range

    ```
    Log::range('error_rate', ['gte'=>20, 'lte'=>80])->get();

    ```
20. rangeBetween - get the result set between a range (Simplified version of range)

    ```
    Log::rangeBetween('error_rate', 20, 30)->get();
    20 -> gte
    30 -> lte

    ```
21. from - pagination option in elasticsearch \[MySQL offset\] \[only applicable for 10000 result window, scroll is encouraged for bigger pagination\]

    ```
    Log::match('field', 'text')->size(100)->from(200)->get()

    ```
22. paginate - pagination added \[LengthAwarePaginator\] Using this api will give you the complete function access of paginator in laravel

    ```
    Log::match('field', 'text')->paginate($perPage, $page)

    ```

    Note - This can be used in the space of first 10000 result set for the current query. So if you intend to use the whole result set, then the better option is to use the scroller.
23. search or searchRaw - To search by the raw array query

    ```
    Log::search([
        'body'=>[
            "query"=>[
                "match" => [
                    "field" => "text"
                ]
            ]
        ]
    ])->get()

    ```

    Note - For query format check the official documentation elasticsearch PHP package
24. topHits - to get the top hits of a aggregation

    ```
    Log::aggs(function(){
        $query->terms('user.id')-aggs(function(){
            $query->topHits()->size(5);  // get top 5 hits of the user
        }, 'hits');
    }, 'users')

    ```
25. multiMatch - To search on multiple fields

    ```
    Log::multiMatch(['user','error'], 'query', 'phrase_prefix');

    ```
26. fromType - To search on specific type

    ```
    Log::match('field', 'text')->fromType('warinings')->get()

    ```
27. find - Find the document by its ID

    ```
    Log::find("AWAMbhhhXkO5BRWWZAw6");

    ```
28. updateByQuery (experimental) - Update the documents using query (Not production ready)

    ```
    Log::match('field', 'test')->script("doc['update_field'].value = update_value")->updateByQuery()

    ```

Notes
=====

[](#notes)

1. Following field names are reserved - \_id, \_type, \_index, \_highlight

TODO
====

[](#todo)

1. Write test cases (stable version)
2. Adding More functionalities
3. Indexing functionalities
4. Mysql query format support

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

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

Recently: every ~40 days

Total

31

Last Release

3023d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10695611?v=4)[Tamizh](/maintainers/rtamizh)[@rtamizh](https://github.com/rtamizh)

---

Top Contributors

[![rtamizh](https://avatars.githubusercontent.com/u/10695611?v=4)](https://github.com/rtamizh "rtamizh (7 commits)")[![aeoris](https://avatars.githubusercontent.com/u/3284058?v=4)](https://github.com/aeoris "aeoris (1 commits)")

---

Tags

elasticsearchlaravelormpackagephp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tamizh-laravel-es/health.svg)

```
[![Health](https://phpackages.com/badges/tamizh-laravel-es/health.svg)](https://phpackages.com/packages/tamizh-laravel-es)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[magento/community-edition

Magento 2 (Open Source)

12.1k53.0k12](/packages/magento-community-edition)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

84735.1k](/packages/flow-php-flow)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[mahocommerce/maho

Free and open source ecommerce platform, created in 2024 on the M1 platform, PHP 8.3+

1384.8k32](/packages/mahocommerce-maho)

PHPackages © 2026

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