PHPackages                             hzx/hyperf-elasticsearch - 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. [Search &amp; Filtering](/categories/search)
4. /
5. hzx/hyperf-elasticsearch

ActiveLibrary[Search &amp; Filtering](/categories/search)

hzx/hyperf-elasticsearch
========================

1.0.3(3y ago)11.1kMITPHPPHP &gt;=7.3

Since Mar 31Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Wonghzx/hyperf-elasticsearch)[ Packagist](https://packagist.org/packages/hzx/hyperf-elasticsearch)[ RSS](/packages/hzx-hyperf-elasticsearch/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (12)Versions (5)Used By (0)

Hyperf Elasticsearch
====================

[](#hyperf-elasticsearch)

根据 [crcms/elasticsearch](https://github.com/crcms/elasticsearch) 改造的基于Hyperf框架的ElasticSearch组件。

Elasticsearch Versionhzx/elasticsearch&gt; = 7.0master(beta unstable)&gt; = 6.01.\*&gt; = 5.0, &lt; 6.00.\*1、安装
----

[](#1安装)

```
composer require hzx/elasticsearch

```

### 2、发布配置

[](#2发布配置)

```
php bin/hyperf.php elasticsearch:publish --config
或
php bin/hyperf.php vendor:publish hzx/elasticsearch
```

### 使用：

[](#使用)

```
$esf = new ElasticsearchFactory();
$builder = $esf->builder()->index('index')->whereTerm('id', '1')->first();
```

```
$builder->index('index')->type('type')->create([
    'key' => 'value'
]);

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

### Update

[](#update)

```
$builder->index('index')->type('type')->update([
    'key' => 'value1'
]);
```

### Delete

[](#delete)

```
$builder->index('index')->type('type')->delete($result->_id);
```

### Select

[](#select)

```
$builder = $builder->index('index')->type('type');

//SQL:select ... where id = 1 limit 1;
$result = $builder->whereTerm('id',1)->first();

//SQL:select ... where (key=1 or key=2) and key1=1
$result = $builder->where(function (Query $inQuery) {
    $inQuery->whereTerm('key',1)->orWhereTerm('key',2)
})->whereTerm('key1',1)->get();
```

skip / take

```
$builder->take(10)->get(); // or limit(10)
$builder->offset(10)->take(10)->get(); // or skip(10)
```

term query

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

match query

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

range query

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

where in query

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

logic query

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

nested query

```
$result = $builder->where(function (Builder $inQuery) {
    $inQuery->whereTerm('key',1)->orWhereTerm('key',2)
})->whereTerm('key1',1)->get();
```

### 条件

[](#条件)

```
public function select($columns): self
```

```
public function where($column, $operator = null, $value = null, $leaf = 'term', $boolean = 'and'): self
```

```
public function orWhere($field, $operator = null, $value = null, $leaf = 'term'): self
```

```
public function whereMatch($field, $value, $boolean = 'and'): self
```

```
public function orWhereMatch($field, $value, $boolean = 'and'): self
```

```
public function whereTerm($field, $value, $boolean = 'and'): self
```

```
public function whereIn($field, array $value)
```

```
public function orWhereIn($field, array $value)
```

```
public function orWhereTerm($field, $value, $boolean = 'or'): self
```

```
public function whereRange($field, $operator = null, $value = null, $boolean = 'and'): self
```

```
public function orWhereRange($field, $operator = null, $value = null): self
```

```
public function whereBetween($field, array $values, $boolean = 'and'): self
```

```
public function whereNotBetween($field, array $values): self
```

```
public function orWhereNotBetween(string $field, array $values): self
```

```
public function whereExists($field, $boolean = 'and'): self
```

```
public function whereNotExists($field, $boolean = 'and'): self
```

```
public function orWhereBetween($field, array $values): self
```

```
public function orderBy(string $field, $sort): self
```

```
public function scroll(string $scroll): self
```

```
public function aggBy($field, $type): self
```

```
public function select($columns): self
```

### 方法

[](#方法)

```
public function get(): Collection
```

```
public function paginate(int $page, int $perPage = 15): Collection
```

```
public function first()
```

```
public function byId($id)
```

```
public function byIdOrFail($id): stdClass
```

```
public function chunk(callable $callback, $limit = 2000, $scroll = '10m')
```

```
public function create(array $data, $id = null, $key = 'id'): stdClass
```

```
public function update($id, array $data): bool
```

```
public function delete($id)
```

```
public function count(): int
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~176 days

Total

4

Last Release

1346d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/224e66388040572e53ad416f22694ad05bef4d9bba25a3126814ec4b9c7c5d7b?d=identicon)[Wonghzx](/maintainers/Wonghzx)

---

Top Contributors

[![Wonghzx](https://avatars.githubusercontent.com/u/23250999?v=4)](https://github.com/Wonghzx "Wonghzx (2 commits)")

---

Tags

phpsearchelasticsearchelasticdriverenginehyperfscout

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hzx-hyperf-elasticsearch/health.svg)

```
[![Health](https://phpackages.com/badges/hzx-hyperf-elasticsearch/health.svg)](https://phpackages.com/packages/hzx-hyperf-elasticsearch)
```

PHPackages © 2026

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