PHPackages                             gong/php-elasticsearch-orm - 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. gong/php-elasticsearch-orm

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

gong/php-elasticsearch-orm
==========================

For personal use only

0271PHP

Since May 12Pushed 1y agoCompare

[ Source](https://github.com/Mr-GD/elasticsearch-orm)[ Packagist](https://packagist.org/packages/gong/php-elasticsearch-orm)[ RSS](/packages/gong-php-elasticsearch-orm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (1)

PHP ELASTICSEARCH ORM
=====================

[](#php-elasticsearch-orm)

Install
-------

[](#install)

```
composer require vae/php-elasticsearch-orm

```

Support Elasticsearch Version
-----------------------------

[](#support-elasticsearch-version)

> more than 7.0

Use
---

[](#use)

### PHP

[](#php)

```
    //require elasticsearch config
    $config = require "elasticsearch.php";
    //instance
    $builder = Factory::builder($config);
```

### Laravel framework

[](#laravel-framework)

Add the service provider config in `config/app.php`

```
    'providers' => [
        Vae\PhpElasticsearchOrm\Laravel\ElasticsearchOrm\OrmProvider::class,
    ]
```

Use in Code

```
    $builder = app(\Vae\PhpElasticsearchOrm\Builder::class);
```

### Hyperf framework

[](#hyperf-framework)

Use in Code

OrmElasticsearchClientFactory

```
    use \Vae\PhpElasticsearchOrm\Builder;
    use \Vae\PhpElasticsearchOrm\Query;
    use \Vae\PhpElasticsearchOrm\Grammar;
    class OrmElasticsearchClientFactory{
        public static function builder()
        {
            // 如果在协程环境下创建，则会自动使用协程版的 Handler，非协程环境下无改变
            $hyperfBuilder = ApplicationContext::getContainer()->get(ClientBuilderFactory::class)->create();
            $client = $hyperfBuilder->setHosts(['http://127.0.0.1:9200'])->build();
            return new Builder(new Query(new Grammar(), $client));
        }
    }
```

Quickstart
----------

[](#quickstart)

### Create

[](#create)

```
    $builder->index('index')->create(['key' => 'value']);
    //return collection
    $builder->index('index')->createCollection(['key' => 'value']);
```

### Batch Create

[](#batch-create)

```
    $builder->index('index')->batchCreate(
        [
            'key1' => 'v1',
            'key2' => 'v2',
        ],
        [
            'key3' => 'v3',
            'key4' => 'v4',
        ]
    );
```

### Update

[](#update)

```
    $builder->index('index')->update(['key' => 'value']);
    $builder->index('index')->update(['key' => ['key2' => 'value']]);
```

### Batch Update Or Update

[](#batch-update-or-update)

```
    $builder->index('index')->batchUpdateOrCreate(
        [
            'id' => '1',
            'key1' => 'v1',
            'key2' => 'v2',
        ],
        [
            'id' => 2,
            'key3' => 'v3',
            'key4' => 'v4',
        ]
    );
```

### deleteById

[](#deletebyid)

```
    $builder->index('index')->deleteById($id) : bool
```

### delete

[](#delete)

```
    $builder->index('index')->delete()
```

### Select

[](#select)

```
    //select one
    $builder->index('index')->first();
    //select all
    $builder->index('index')->get();
    //select with paginate
    $builder->index('index')->paginate($page, $size) : Collection
    //select by id
    $builder->byId($id) : stdClass
    //select by id if failed throw error
    $builder->byIdOrFail($id) : stdClass
    //select chunk
    $builder->chunk(callback $callback, $limit = 2000, $scroll = '10m')
```

### Count

[](#count)

```
    $builder->count() : int
```

### Condition

[](#condition)

whereTerm

```
    $builder->whereTerm('key', 'value');
```

whereLike（wildcard）

```
    //value without add wildcard '*'
    $builder->whereLike('key', 'value');
```

match

```
    $builder->whereMatch('key', 'value');
```

range

```
    $builder->whereBetween('key', ['value1', 'value2']);
```

where in

```
    $builder->whereIn('key', ['value1', 'value2', ...]);
```

nestedQuery

```
    $builder->where(function(Builder $query){
        $query->whereTerm('key', 'value');
    });
```

search nested data

```
    $nestedColumn = "nested_column";
    $builder->whereNested($nestedColumn, function ($query) {
        $query->where('key1', 'value1')
        $query->where('key2', 'value2')
    });
```

```
    $nestedKey = "nested_key";
    $key = "key";
    $builder->where("{$nestedKey}@{$key}", '=', 'value');
```

### Where Support Operator

[](#where-support-operator)

> \['=' =&gt; 'eq','&gt;' =&gt; 'gt','&gt;=' =&gt; 'gte','&lt;' =&gt; 'lt','&lt;=' =&gt; 'lte','!=' =&gt; 'ne',\]

```
    $builder->where('key', '=', 'value');
```

### More

[](#more)

see file `Vae\PhpElasticsearchOrm\Builder`

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 66.7% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b98f12a97816c994c167bb04c0f61ab45f1d60ff2fae468076dde5757f6475bd?d=identicon)[mr.gong](/maintainers/mr.gong)

---

Top Contributors

[![vae-s](https://avatars.githubusercontent.com/u/53052986?v=4)](https://github.com/vae-s "vae-s (6 commits)")[![Mr-GD](https://avatars.githubusercontent.com/u/40883716?v=4)](https://github.com/Mr-GD "Mr-GD (3 commits)")

### Embed Badge

![Health badge](/badges/gong-php-elasticsearch-orm/health.svg)

```
[![Health](https://phpackages.com/badges/gong-php-elasticsearch-orm/health.svg)](https://phpackages.com/packages/gong-php-elasticsearch-orm)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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