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

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

carterzhou/elasticsearch
========================

A Laravel package provides fluent API to work with Elasticsearch

1.0.5(7y ago)07MITPHP

Since Jan 29Pushed 7y ago1 watchersCompare

[ Source](https://github.com/CarterZhou/elasticsearch)[ Packagist](https://packagist.org/packages/carterzhou/elasticsearch)[ Docs](https://github.com/carterzhou/elasticsearch)[ RSS](/packages/carterzhou-elasticsearch/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (7)Used By (0)

Laravel fluent APIs to work with Elasticsearch
==============================================

[](#laravel-fluent-apis-to-work-with-elasticsearch)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3ab842394e64f5eb34ca260d8bb4c5dc7547ae28b70078fe9da92e29309053dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6361727465727a686f752f656c61737469637365617263682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/carterzhou/elasticsearch)[![Total Downloads](https://camo.githubusercontent.com/ca2be7efaa084062e85fa0b68b9b336299a5d716bdd47b8e4f00070495ddf0f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6361727465727a686f752f656c61737469637365617263682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/carterzhou/elasticsearch)

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

[](#installation)

Via Composer

```
$ composer require carterzhou/elasticsearch
```

Usage
-----

[](#usage)

Firstly, create an instance of this class. Here we use dependency injection to let Laravel create and inject an instance for us.

```
use CarterZhou\Elasticsearch\Client;

class TestController extends Controller
{
    protected $client;

    /**
     * TestController constructor.
     * @param Client $client
     */
    public function __construct(Client $client)
    {
        $this->client = $client;
    }
}
```

- Doing simple search

Then we can use `search` method to grab data from Elasticsearch. Notice that we can chain `match` method to add filtering conditions (similar to Eloquent `where` method).

```
$url = $this->client->getHost() . '/indices-2019.01.28';

$this->client
    ->match('request', 'one-of-urls')
    ->match('request', 'field1 field2')
    ->setSize(500);

$this->client->search($url);

if ($this->client->hasDocuments()) {
    foreach ($this->client->getDocuments() as $document) {
        // Process your document here...
    }
}
```

- Search for all documents. You can also communicate with Elasticsearch multiple times to get documents if total of matching documents exceeds the size you set.

```
$url = $this->client->getHost() . '/indices-2019.01.28';

$this->client
    ->match('request', 'one-of-urls')
    ->match('request', 'field1 field2')
    ->setSize(500);

do {
    $this->client->search($url);

    if ($this->client->hasDocuments()) {

        foreach ($this->client->getDocuments() as $redirect) {
            // Process your document here...
        }
    }
} while ($this->client->hasMoreDocuments());
```

Notice that we use a `do while` loop here because a search will be performed at least once. You don't have to manually set "from" because the `search` method will calculate and maintain properties including "from" under the hood.

Warning: you should not use `search` method if total of matching documents is over 10000, because by default the result window is 10000 by using "from" to do query. In such case, please use `scroll` method instead.

- Use scrolling

As stated above, do not use `search` method to loop through large result sets because normally you are not allowed to do so. To address such need, you can use `scroll` method like so

```
$url = $this->client->getHost() . '/logstash*';

$this->client->matchAll()->setSize(500);

$this->client->scroll($url);

do {
    foreach ($this->client->getDocuments() as $document) {
        // Process your document here...
    }

    $this->client->scroll($url);

} while ($this->client->hasDocuments());
```

Change log
----------

[](#change-log)

Please see the [changelog](changelog.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todolist.

Security
--------

[](#security)

If you discover any security related issues, please email author email instead of using the issue tracker.

License
-------

[](#license)

license. Please see the [license file](license.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 95% 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 ~1 days

Total

6

Last Release

2656d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ea12870e6e733064a22064f65589d4d710ba6f116f54aa3ce45039b1fa5a246?d=identicon)[CarterZhou](/maintainers/CarterZhou)

---

Top Contributors

[![CarterCga](https://avatars.githubusercontent.com/u/86387430?v=4)](https://github.com/CarterCga "CarterCga (19 commits)")[![CarterZhou](https://avatars.githubusercontent.com/u/1753933?v=4)](https://github.com/CarterZhou "CarterZhou (1 commits)")

---

Tags

laravelelasticsearch

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[baijunyao/laravel-scout-elasticsearch

Elasticsearch Driver for Laravel Scout

8023.7k1](/packages/baijunyao-laravel-scout-elasticsearch)

PHPackages © 2026

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