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

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

alexsaab/laravel-elasticsearch
==============================

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

4.1.1(6y ago)04MITPHPPHP ^7.2

Since May 28Pushed 6y agoCompare

[ Source](https://github.com/alexsaab/laravel-elasticsearch)[ Packagist](https://packagist.org/packages/alexsaab/laravel-elasticsearch)[ Docs](https://github.com/cviebrock/laravel-elasticsearch)[ RSS](/packages/alexsaab-laravel-elasticsearch/feed)WikiDiscussions master Synced yesterday

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

Laravel-Elasticsearch
=====================

[](#laravel-elasticsearch)

An easy way to use the [official Elastic Search client](https://github.com/elastic/elasticsearch-php) in your Laravel or Lumen applications.

[![Build Status](https://camo.githubusercontent.com/f04b368a52dab32c6d863ff68985986684c389811ccbc8ae950ade0324b19220/68747470733a2f2f7472617669732d63692e6f72672f616c6578736161622f6c61726176656c2d656c61737469637365617263682e737667)](https://travis-ci.org/alexsaab/laravel-elasticsearch)[![Total Downloads](https://camo.githubusercontent.com/1539d85670662a29969682e733f2c763e830bd99e961921f2274c0018a771acd/68747470733a2f2f706f7365722e707567782e6f72672f616c6578736161622f6c61726176656c2d656c61737469637365617263682f646f776e6c6f6164732e706e67)](https://packagist.org/packages/alexsaab/laravel-elasticsearch)[![Latest Stable Version](https://camo.githubusercontent.com/d14119346f29b5b0e655ca39750f320d40d8224ff3cdfb2230d2559d3513eb9f/68747470733a2f2f706f7365722e707567782e6f72672f616c6578736161622f6c61726176656c2d656c61737469637365617263682f762f737461626c652e706e67)](https://packagist.org/packages/alexsaab/laravel-elasticsearch)[![Latest Stable Version](https://camo.githubusercontent.com/e34c4f4b616e6e8c9d96615ce5efaddfa2b4cc6dbacfb5f88cf7edd753bff387/68747470733a2f2f706f7365722e707567782e6f72672f616c6578736161622f6c61726176656c2d656c61737469637365617263682f762f756e737461626c652e706e67)](https://packagist.org/packages/alexsaab/laravel-elasticsearch)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d4c3789c7e442d32cc7ff7e0a1f6821d7ff1010d268d3f1eb40616a72dad719b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c6578736161622f6c61726176656c2d656c61737469637365617263682f6261646765732f7175616c6974792d73636f72652e706e673f666f726d61743d666c6174)](https://scrutinizer-ci.com/g/alexsaab/laravel-elasticsearch)

- [Installation and Configuration](#installation-and-configuration)
- [Usage](#usage)
- [Advanced Usage](#advanced-usage)
- [Bugs, Suggestions, Contributions and Support](#bugs-suggestions-contributions-and-support)
- [Copyright and License](#copyright-and-license)

Installation and Configuration
------------------------------

[](#installation-and-configuration)

Install the current version of the `alexsaab/laravel-elasticsearch` package via composer:

```
composer require alexsaab/laravel-elasticsearch
```

If you are using ElasticSearch version 5, then install version 2 of this package:

```
composer require alexsaab/laravel-elasticsearch:^2
```

### Laravel

[](#laravel)

The package's service provider will automatically register its service provider.

Publish the configuration file:

```
php artisan vendor:publish --provider="Alexsaab\LaravelElasticsearch\ServiceProvider"
```

##### Alternative configuration method via .env file

[](#alternative-configuration-method-via-env-file)

After you publish the configuration file as suggested above, you may configure ElasticSearch by adding the following to your application's `.env` file (with appropriate values):

```
ELASTICSEARCH_HOST=localhost
ELASTICSEARCH_PORT=9200
ELASTICSEARCH_SCHEME=http
ELASTICSEARCH_USER=
ELASTICSEARCH_PASS=
```

##### Connecting to AWS Elasticsearch Service

[](#connecting-to-aws-elasticsearch-service)

If you are connecting to ElasticSearch instances on Amazon AWS, then you'll also need to `composer require aws/aws-sdk-php:^3.80` and add the following to your `.env` file:

```
AWS_ELASTICSEARCH_ENABLED=true
AWS_REGION=...
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
```

### Lumen

[](#lumen)

If you work with Lumen, please register the service provider and configuration in `bootstrap/app.php`:

```
$app->register(Alexsaab\LaravelElasticsearch\ServiceProvider::class);
$app->configure('elasticsearch');
```

Manually copy the configuration file to your application.

Usage
-----

[](#usage)

The `Elasticsearch` facade is just an entry point into the [ES client](https://github.com/elastic/elasticsearch-php), so previously you might have used:

```
$data = [
    'body' => [
        'testField' => 'abc'
    ],
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id',
];

$client = ClientBuilder::create()->build();
$return = $client->index($data);
```

You can now replace those last two lines with simply:

```
$return = Elasticsearch::index($data);
```

That will run the command on the default connection. You can run a command on any connection (see the `defaultConnection` setting and `connections` array in the configuration file).

```
$return = Elasticsearch::connection('connectionName')->index($data);
```

Lumen users who wish to use Facades can do so by editing the `bootstrap/app.php` file to include the following:

```
$app->withFacades(true, [
    ...
    Alexsaab\LaravelElasticsearch\Facade::class => 'Elasticsearch',
    ...
]);
```

Lumen users who aren't using facades will need to use dependency injection or the application container in order to get the ES service object:

```
// using injection:
public function handle(\Alexsaab\LaravelElasticsearch\Manager $elasticsearch)
{
    $elasticsearch->ping();
}

// using application container:
$elasticSearch = $this->app('elasticsearch');
```

Of course, dependency injection and the application container work for Laravel applications as well.

Advanced Usage
--------------

[](#advanced-usage)

Because the package is a wrapper around the official Elastic client, you can do pretty much anything with this package. Not only can you perform standard CRUD operations, but you can monitor the health of your Elastic cluster programmatically, back it up, or make changes to it. Some of these operations are done through "namespaced" commands, which this package happily supports.

To grab statistics for an index:

```
$stats = Elasticsearch::indices()->stats(['index' => 'my_index']);
$stats = Elasticsearch::nodes()->stats();
$stats = Elasticsearch::cluster()->stats();
```

To create and restore snapshots (read the Elastic docs about creating repository paths and plugins first):

```
$response = Elasticsearch::snapshots()->create($params);
$response = Elasticsearch::snapshots()->restore($params);
```

To delete whole indices (be careful!):

```
$response = Elasticsearch::indices()->delete(['index' => 'my_index']);
```

Please remember that this package is a thin wrapper around a large number of very sophisticated and well-documented Elastic features. Information about those features and the methods and parameters used to call them can be found in the [Elastic documentation](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html). Help with using them is available via the [Elastic forums](https://discuss.elastic.co/)and on sites like [Stack Overflow](https://stackoverflow.com/questions/tagged/elasticsearch).

Bugs, Suggestions, Contributions and Support
--------------------------------------------

[](#bugs-suggestions-contributions-and-support)

Thanks to [everyone](https://github.com/alexsaab/laravel-elasticsearch/graphs/contributors)who has contributed to this project!

Special thanks to [JetBrains](https://www.jetbrains.com/?from=alexsaab/laravel-elasticsearch) for their Open Source License Program ... and the excellent PHPStorm IDE, of course!

[![JetBrains](./.github/jetbrains.svg)](https://www.jetbrains.com/?from=alexsaab/laravel-elasticsearch)

Please use [Github](https://github.com/alexsaab/laravel-elasticsearch) for reporting bugs, and making comments or suggestions.

See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute changes.

Copyright and License
---------------------

[](#copyright-and-license)

[laravel-elasticsearch](https://github.com/alexsaab/laravel-elasticsearch)was written by [Colin Viebrock](http://viebrock.ca) and is released under the [MIT License](LICENSE.md).

Copyright (c) 2015 Colin Viebrock

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~68 days

Recently: every ~34 days

Total

24

Last Release

2433d ago

Major Versions

0.9.3 → 1.0.02016-01-06

1.3.0 → 2.0.02017-05-04

2.0.x-dev → 3.0.02017-11-29

3.6.0 → 4.0.02019-08-31

PHP version history (4 changes)0.9.0PHP &gt;=5.4.0

3.0.0PHP ^7.0

4.0.0PHP ^7.1

4.1.0PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed61a4da4e7189b6121bd33de1930cf5188254ca0537cf3e29746ea5ea107b21?d=identicon)[alexsaab](/maintainers/alexsaab)

---

Top Contributors

[![cviebrock](https://avatars.githubusercontent.com/u/166810?v=4)](https://github.com/cviebrock "cviebrock (28 commits)")[![petercoles](https://avatars.githubusercontent.com/u/2947594?v=4)](https://github.com/petercoles "petercoles (7 commits)")[![khoatran](https://avatars.githubusercontent.com/u/1765656?v=4)](https://github.com/khoatran "khoatran (4 commits)")[![xian13](https://avatars.githubusercontent.com/u/2676750?v=4)](https://github.com/xian13 "xian13 (3 commits)")[![alexsaab](https://avatars.githubusercontent.com/u/5072709?v=4)](https://github.com/alexsaab "alexsaab (3 commits)")[![Matrix86](https://avatars.githubusercontent.com/u/244997?v=4)](https://github.com/Matrix86 "Matrix86 (3 commits)")[![Harrisonbro](https://avatars.githubusercontent.com/u/377366?v=4)](https://github.com/Harrisonbro "Harrisonbro (2 commits)")[![bmartel](https://avatars.githubusercontent.com/u/2242258?v=4)](https://github.com/bmartel "bmartel (2 commits)")[![pavel-pepper](https://avatars.githubusercontent.com/u/143077375?v=4)](https://github.com/pavel-pepper "pavel-pepper (1 commits)")[![ristedavcevski](https://avatars.githubusercontent.com/u/12125687?v=4)](https://github.com/ristedavcevski "ristedavcevski (1 commits)")[![SirNarsh](https://avatars.githubusercontent.com/u/13707877?v=4)](https://github.com/SirNarsh "SirNarsh (1 commits)")[![tufanbarisyildirim](https://avatars.githubusercontent.com/u/980848?v=4)](https://github.com/tufanbarisyildirim "tufanbarisyildirim (1 commits)")[![Lednerb](https://avatars.githubusercontent.com/u/2056876?v=4)](https://github.com/Lednerb "Lednerb (1 commits)")[![ahmedash95](https://avatars.githubusercontent.com/u/8272048?v=4)](https://github.com/ahmedash95 "ahmedash95 (1 commits)")[![axe-me](https://avatars.githubusercontent.com/u/3348648?v=4)](https://github.com/axe-me "axe-me (1 commits)")[![bburr](https://avatars.githubusercontent.com/u/797289?v=4)](https://github.com/bburr "bburr (1 commits)")[![james-brown-upfeat](https://avatars.githubusercontent.com/u/125611187?v=4)](https://github.com/james-brown-upfeat "james-brown-upfeat (1 commits)")[![303K](https://avatars.githubusercontent.com/u/3934941?v=4)](https://github.com/303K "303K (1 commits)")[![matejvelikonja](https://avatars.githubusercontent.com/u/1881087?v=4)](https://github.com/matejvelikonja "matejvelikonja (1 commits)")[![okdewit](https://avatars.githubusercontent.com/u/1403548?v=4)](https://github.com/okdewit "okdewit (1 commits)")

---

Tags

clientsearchlaravelelasticsearch

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/alexsaab-laravel-elasticsearch/health.svg)](https://phpackages.com/packages/alexsaab-laravel-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)[gtk/larasearch

A driver based solution to searching your Eloquent models supports Laravel 5.2 and Elasticsearch engine.

133.9k](/packages/gtk-larasearch)

PHPackages © 2026

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