PHPackages                             friendsofhyperf/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. friendsofhyperf/elasticsearch

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

friendsofhyperf/elasticsearch
=============================

Elasticsearch client for hyperf

v3.2.1(3w ago)32.1kMITPHP

Since May 17Pushed 2w ago2 watchersCompare

[ Source](https://github.com/friendsofhyperf/elasticsearch)[ Packagist](https://packagist.org/packages/friendsofhyperf/elasticsearch)[ Fund](https://hdj.me/sponsors/)[ GitHub Sponsors](https://github.com/huangdijia)[ RSS](/packages/friendsofhyperf-elasticsearch/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (8)Versions (36)Used By (0)

Elasticsearch
=============

[](#elasticsearch)

[中文说明](README_CN.md)

This component integrates the official Elasticsearch PHP client with Hyperf's Guzzle client and provides a static facade for configured connections.

Requirements
------------

[](#requirements)

The package targets Hyperf 3.2 and requires `elasticsearch/elasticsearch` version 8 or 9, `hyperf/config`, `hyperf/context`, and `hyperf/guzzle`. It does not declare optional dependencies.

Installation
------------

[](#installation)

```
composer require friendsofhyperf/elasticsearch
php bin/hyperf.php vendor:publish friendsofhyperf/elasticsearch
```

The publish command creates `config/autoload/elasticsearch.php`.

Configuration
-------------

[](#configuration)

The published configuration defines the `default` connection. `ELASTICSEARCH_HOST` is split on commas, so it may contain multiple hosts. Additional named connections may be added under `elasticsearch`:

```
return [
    'default' => [
        'hosts' => explode(',', env('ELASTICSEARCH_HOST', '')),
    ],
    'analytics' => [
        'hosts' => ['http://127.0.0.1:9200'],
    ],
];
```

For facade connections, `hosts` may be an array or a comma-separated string. The facade only reads the `hosts` key; configure other client behavior through `ClientBuilderFactory` and the upstream builder.

Usage
-----

[](#usage)

### Client Builder Factory

[](#client-builder-factory)

`ClientBuilderFactory::create(array $options = [])` passes `$options` to Hyperf's `GuzzleClientFactory` and returns an unbuilt upstream `ClientBuilder`. Configure the builder before calling `build()`:

```
use FriendsOfHyperf\Elasticsearch\ClientBuilderFactory;

class Foo
{
    public function __construct(protected ClientBuilderFactory $clientBuilderFactory)
    {
    }

    public function handle()
    {
        $client = $this->clientBuilderFactory
            ->create(['timeout' => 5])
            ->setHosts(['http://127.0.0.1:9200'])
            ->build();

        return $client->info();
    }
}
```

The factory does not read `config/autoload/elasticsearch.php`; hosts and other builder settings must be applied explicitly.

### Facade

[](#facade)

Static facade calls use the `default` connection. Use `connection()` to select a named connection:

```
use FriendsOfHyperf\Elasticsearch\Facade\Elasticsearch;

$info = Elasticsearch::info();
$results = Elasticsearch::connection('analytics')->search([
    'index' => 'articles',
    'body' => [
        'query' => [
            'match_all' => (object) [],
        ],
    ],
]);
```

Each facade call builds a new client. If the selected connection is missing or `null`, the component throws `InvalidArgumentException` with the connection name.

Upstream API
------------

[](#upstream-api)

Client methods, request parameters, response objects, authentication, and additional builder options are provided by the installed `elasticsearch/elasticsearch` version. Refer to the matching upstream client documentation when using them.

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance96

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

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

###  Release Activity

Cadence

Every ~54 days

Recently: every ~48 days

Total

35

Last Release

24d ago

Major Versions

0.6.0 → 1.x-dev2022-03-07

0.x-dev → v3.1.02024-03-05

PHP version history (3 changes)0.3.2PHP &gt;=7.3

1.x-devPHP &gt;=8.0

v3.1.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8337659?v=4)[Deeka Wong](/maintainers/huangdijia)[@huangdijia](https://github.com/huangdijia)

---

Top Contributors

[![huangdijia](https://avatars.githubusercontent.com/u/8337659?v=4)](https://github.com/huangdijia "huangdijia (18 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (1 commits)")

---

Tags

phpelasticsearchswoole

### Embed Badge

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

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

###  Alternatives

[hyperf/hyperf-skeleton

A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.

313190.9k](/packages/hyperf-hyperf-skeleton)

PHPackages © 2026

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