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

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

triadev/laravel-elasticsearch-dsl
=================================

A service provider for laravel with a fluent elasticsearch query and aggregation dsl.

v1.1.4(7y ago)68911MITPHPPHP &gt;=7.1

Since Dec 24Pushed 7y ago1 watchersCompare

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

READMEChangelogDependencies (10)Versions (9)Used By (1)

laravel-elasticsearch-dsl
=========================

[](#laravel-elasticsearch-dsl)

A service provider for laravel with a fluent elasticsearch query and aggregation dsl.

[![Software license](https://camo.githubusercontent.com/43b99c4f43c0f6321446d89427fc318dee9fbb38259cb28e0d2a53ac6b66348b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f747269616465762f6c61726176656c2d656c61737469637365617263682d64736c2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Travis](https://camo.githubusercontent.com/a10db589b9e46a4221febee55dabfe51d5106bdd706ef194b23f7f290991bba6/68747470733a2f2f7472617669732d63692e6f72672f747269616465762f6c61726176656c2d656c61737469637365617263682d64736c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/triadev/laravel-elasticsearch-dsl)[![Coveralls](https://camo.githubusercontent.com/ec4d80846e1261c75dff60f533546968f619cab2a50b0d1f2266c936b7b9b51e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f747269616465762f6c61726176656c2d656c61737469637365617263682d64736c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/triadev/laravel-elasticsearch-dsl?branch=master)[![CodeCov](https://camo.githubusercontent.com/2813c27800a5195309502f7efbb867eac160eda53187b9d2ab02dd6a3a3c5ef8/68747470733a2f2f636f6465636f762e696f2f67682f747269616465762f6c61726176656c2d656c61737469637365617263682d64736c2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/triadev/laravel-elasticsearch-dsl)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ad882b2c9c94061e506e341199c0e798c1bf31021238d95aca990cb8188c26f5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f747269616465762f6c61726176656c2d656c61737469637365617263682d64736c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/triadev/laravel-elasticsearch-dsl/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/cd5a783bee13920d84e22a384722af5458c555c9da5084d49e7980237d4571a6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f747269616465762f6c61726176656c2d656c61737469637365617263682d64736c2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/triadev/laravel-elasticsearch-dsl/?branch=master)[![Build Status](https://camo.githubusercontent.com/0699cde29874f24c3db956ef693e6f48d806a9b4ae4447104cd7c0c45d830d27/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f747269616465762f6c61726176656c2d656c61737469637365617263682d64736c2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/triadev/laravel-elasticsearch-dsl/build-status/master)

[![Latest stable](https://camo.githubusercontent.com/3c5547061682a129a21568d48d9b4fb2675a45af0f4d4aa2db3393055efd0d61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f747269616465762f6c61726176656c2d656c61737469637365617263682d64736c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/triadev/laravel-elasticsearch-dsl)[![Latest development](https://camo.githubusercontent.com/ace6c7f1e58cea7fed36e867d0a5839c38a515fbb302c927aa931f4990cac0a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f747269616465762f6c61726176656c2d656c61737469637365617263682d64736c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/triadev/laravel-elasticsearch-dsl)[![Monthly installs](https://camo.githubusercontent.com/f6c602a57787a722bda7117c18ef4676d784d6f9a42101918deb1773b6dde568/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f747269616465762f6c61726176656c2d656c61737469637365617263682d64736c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/triadev/laravel-elasticsearch-dsl/stats)

Supported laravel versions
--------------------------

[](#supported-laravel-versions)

[![Laravel 5.5](https://camo.githubusercontent.com/1bd291589054cd0fea96c97b26e57f7dfd024f3d20572a13a74a64e37aa053d6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e352d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)[![Laravel 5.6](https://camo.githubusercontent.com/19208e4e17c5a44f6eeb2ca49987cf944b671fbd1069f1e5cc006c509f119e2b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e362d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)[![Laravel 5.7](https://camo.githubusercontent.com/01e109b20d194f8c9f7398bde86682d9457d92fbf7485b4ffabf6746df741d64/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e372d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)

Supported elasticsearch versions
--------------------------------

[](#supported-elasticsearch-versions)

[![Elasticsearch 6.0](https://camo.githubusercontent.com/810d03fd98470d0400d68f20b1fe4dc219e4a8a887c96ce5ce3b545e71475380/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f456c61737469637365617263682d362e302d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://www.elastic.co/)[![Elasticsearch 6.1](https://camo.githubusercontent.com/bc2e01ea13c32ac5cb11c1a7dce2abf6d98891c8f4697973715b6f9a5447192c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f456c61737469637365617263682d362e312d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://www.elastic.co/)[![Elasticsearch 6.2](https://camo.githubusercontent.com/6f0ef3d891eaf0eeb74cb60fdc5c7a74bfe5879aa428ecc5758dea885fc2f920/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f456c61737469637365617263682d362e322d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://www.elastic.co/)[![Elasticsearch 6.3](https://camo.githubusercontent.com/93ac37d9096d3c081e5a46d1a0aea549f2fe8b8a09bab0fefe2c85a753e55fac/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f456c61737469637365617263682d362e332d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://www.elastic.co/)[![Elasticsearch 6.4](https://camo.githubusercontent.com/922fceaef72c0a5ab286fd0b454b5c477b97c51b0e13037edd5f763971c9e711/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f456c61737469637365617263682d362e342d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://www.elastic.co/)

Main features
-------------

[](#main-features)

- Query (TermLevel, Fulltext, Geo, Compound, Joining, Specialized, InnerHit)
- Aggregation (Bucketing, Metric, Pipeline)
- Suggestion

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

[](#installation)

### Composer

[](#composer)

> composer require triadev/laravel-elasticsearch-dsl

### Application

[](#application)

The package is registered through the package discovery of laravel and Composer.

>

Once installed you can now publish your config file and set your correct configuration for using the package.

```
php artisan vendor:publish --provider="Triadev\Es\Dsl\Provider\ServiceProvider" --tag="config"
```

This will create a file `config/laravel-elasticsearch-dsl.php`.

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

[](#configuration)

KeyEnvValueDefaultindexLARAVEL\_ELASTICSEARCH\_DSL\_INDEXSTRINGdefault\_indexmetrics.enabledLARAVEL\_ELASTICSEARCH\_DSL\_METRICSBOOLfalsemetrics.buckets.search---ARRAYarray of buckets in millisecondsmetrics.buckets.suggest---ARRAYarray of buckets in millisecondsMetrics
-------

[](#metrics)

Metrics are generated with the package: [LaravelPrometheusExporter](https://github.com/triadev/LaravelPrometheusExporter)
Detailed configuration options are documented in the readme of the package.

The following metrics are generated as long as `metrics.enabled = true`:

> Namespace: triadev\_laravel\_elasticsearch\_dsl

### Histogram

[](#histogram)

NameHandlerDescriptionquery\_duration\_millisecondssearchexecution time of search queryquery\_duration\_millisecondssuggestexecution time of suggestion queryUsage
-----

[](#usage)

This package offers a dsl for elasticsearch. The entry point for each query / aggregation is a facade.

> Triadev\\Es\\Dsl\\Facade\\ElasticDsl;

Each query / aggregation returns an object containing the search result and aggregation.

> Triadev\\Es\\Dsl\\Model\\SearchResult

```
int: time needed to execute the query
$result->took();

bool
$result->timedOut();

float
$result->maxScore();

int: number of matched documents
$result->totalHits();

Illuminate\Support\Collection: collection of searchable eloquent models
$result->hits();

array|null
$result->aggregation();
```

### Bool

[](#bool)

For every query that is based on bool, the bool status can be changed.

> Default bool state: must

```
ElasticDsl::search()->termLevel()
    ->must()
        ->term('FIELD', 'VALUE')
    ->mustNot()
        ->term('FIELD', 'VALUE')
    ->should()
        ->term('FIELD', 'VALUE')
    ->filter()
        ->term('FIELD', 'VALUE')
})->get()
```

#### Nested bool query

[](#nested-bool-query)

A nested query is realized with `bool(\Closure $closure)`.

```
ElasticDsl::search()
    ->termLevel()
        ->term('FIELD', 'VALUE')
        ->bool(function (Search $search) {
            $search->termLevel()
                ->term('FIELD', 'VALUE')
                ->bool(function (Search $search) {
                    $search->fulltext()
                        ->match('FIELD1', 'QUERY1')
                        ->matchPhrase('FIELD2', 'QUERY2');
                });
            })
        ->prefix('FIELD', 'VALUE')
    ->get();

--------------------------------------------------
[
    "query" => [
        "bool" => [
            "must" => [
                [
                    "term" => [
                        "FIELD" => "VALUE"
                    ]
                ],
                [
                    "bool" => [
                        "must" => [
                            [...],
                            [...]
                        ]
                    ]
                ],
                [
                    "prefix" => [
                        "FIELD" => [
                            "value" => "VALUE"
                        ]
                    ]
                ]
            ]
        ]
    ]
]
```

### TermLevel

[](#termlevel)

> matchAll, exists, fuzzy, ids, prefix, range, regexp, term, terms, type, wildcard

```
ElasticDsl::search()->termLevel()->filter()->term('FIELD', 'VALUE')->get();
```

### Fulltext

[](#fulltext)

> match, matchPhrase, matchPhrasePrefix, multiMatch, queryString, simpleQueryString, commonTerms

```
ElasticDsl::search()->fulltext()->must()->match('FIELD', 'QUERY')->get();
```

### Geo

[](#geo)

> geoBoundingBox, geoDistance, geoPolygon, geoShape

```
ElasticDsl::search()->geo()->filter()->geoDistance('FIELD','10km', new Location(1, 2))->get();
```

### Compound

[](#compound)

> functionScore, constantScore, boosting, disMax

```
ElasticDsl::search()->compound()->functionScore(
    function (Search $search) {
        $search->termLevel()->term('FIELD1', 'VALUE1');
    },
    function (FunctionScore $functionScore) {
        $functionScore->simple([]);
    }
)->get();
```

### Joining

[](#joining)

> nested, hasChild, hasParent

```
ElasticDsl::search()->joining()->nested('PATH', function (Search $search) {
   $search->termLevel()->filter()->term('FIELD', 'VALUE');
})->get();
```

### Specialized

[](#specialized)

> moreLikeThis

```
ElasticDsl::search()->specialized()->moreLikeThis('LIKE')->toDsl();
```

### InnerHit

[](#innerhit)

> nestedInnerHit, parentInnerHit

```
ElasticDsl::search()->nestedInnerHit('NAME', 'PATH', function (Search $search) {
    $search->termLevel()->term('FIELD', 'VALUE');
})->get();
```

#### Individual index and type

[](#individual-index-and-type)

To set an individual index or type per query you have two overwrite methods.

```
ElasticDsl::search()
    ->overwriteIndex('INDEX')
    ->overwriteType('TYPE')
    ->termLevel()
        ->matchAll()
    ->get();
```

### Aggregation

[](#aggregation)

> Bucketing, Metric, Pipeline

```
ElasticDsl::search()->aggregation(function (Aggregation $aggregation) {
    $aggregation->metric(function (Aggregation\Metric $metric) {
        ...
    });
})->get();

ElasticDsl::search()->aggregation(function (Aggregation $aggregation) {
    $aggregation->bucketing(function (Aggregation\Bucketing $metric) {
        ...
    });
})->get();

ElasticDsl::search()->aggregation(function (Aggregation $aggregation) {
    $aggregation->pipeline(function (Aggregation\Pipeline $metric) {
        ...
    });
})->get();
```

### Suggestions

[](#suggestions)

> term, phrase, completion

```
ElasticDsl::suggest()->term('NAME', 'TEXT', 'FIELD')->get();
```

Reporting Issues
----------------

[](#reporting-issues)

If you do find an issue, please feel free to report it with GitHub's bug tracker for this project.

Alternatively, fork the project and make a pull request. :)

Testing
-------

[](#testing)

1. docker-compose -f docker-compose.yml up
2. composer test

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Christopher Lorke](https://github.com/triadev)
- [All Contributors](../../contributors)

Other
-----

[](#other)

### Project related links

[](#project-related-links)

- [Wiki](https://github.com/triadev/laravel-elasticsearch-dsl/wiki)
- [Issue tracker](https://github.com/triadev/laravel-elasticsearch-dsl/issues)

### License

[](#license)

The code for laravel-elasticsearch-dsl is distributed under the terms of the MIT license (see [LICENSE](LICENSE)).

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Total

6

Last Release

2682d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/806ca8236e565a4a76aaad0ad4382dc52f1bc4b7850712878e1fb89826cd2bb8?d=identicon)[triadev](/maintainers/triadev)

---

Top Contributors

[![triadev](https://avatars.githubusercontent.com/u/10552858?v=4)](https://github.com/triadev "triadev (6 commits)")

---

Tags

dslelasticsearchlaravellaravelelasticsearchDSL

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  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)

PHPackages © 2026

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