PHPackages                             jeffleyd/esquery - 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. jeffleyd/esquery

ActiveLibrary

jeffleyd/esquery
================

Use syntax similar to eloquent, using the elastic search service.

v1.1.6(3y ago)122MITPHPPHP &gt;=8.0

Since Mar 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/jeffleyd/EsQuery)[ Packagist](https://packagist.org/packages/jeffleyd/esquery)[ RSS](/packages/jeffleyd-esquery/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (18)Used By (0)

EsQuery
-------

[](#esquery)

This project is to be similar to the eloquent query, like this facilitating searches in ElasticSearch's **Lucene**.

```
composer require jeffleyd/esquery

```

#### PUBLISH THE FILE CONFIG

[](#publish-the-file-config)

```
php artisan vendor:publish --tag="esquery-provider"

```

Access the config folder and change the settings of the esquery.php file.

#### USAGE EXAMPLES

[](#usage-examples)

##### First create a mapping for your index

[](#first-create-a-mapping-for-your-index)

###### For more information about mapping types:

[](#for-more-information-about-mapping-types-httpswwwelasticcoguideenelasticsearchreferencecurrentmapping-typeshtml)

```
$build = EsQuery::index('my_index');
$response = $build->createIndex([
        'mappings' => [
            'properties' => [
                'parent_id' => [
                    'type' => 'long',
                ],
                'created_at' => [
                    'type' => 'date',
                    'format' => 'yyyy-MM-dd HH:mm:ss||yyyy-MM-dd'
                ]
            ]
        ]
    ]);

```

##### If you want to add a new index, you can do it like this

[](#if-you-want-to-add-a-new-index-you-can-do-it-like-this)

##### Create a migration file and extend the EsScheme class

[](#create-a-migration-file-and-extend-the-esscheme-class)

```
    public function up()
    {
        EsScheme::create('bosses', function (EsMapping $table) {
            $table->integer('id');
            $table->string('name');
            $table->string('email');
            $table->nested('json');
            $table->timestamp('created_at');
            $table->timestamp('updated_at');

            // If you want to use a simple analyzer, you can add the following line.
            $table->setDefaultAnalyzer();

            // If you want to use a custom analyzer, you can use the following:
            $table->mapping['settings'] = [
                'analysis' => [
                    'default_analyze' => [
                        'type' => 'custom',
                        'tokenizer' => 'whitespace',
                        'char_filter' => [
                            'html_strip'
                        ],
                        'filter' => [
                            'lowercase'
                        ]
                    ]
                ]
            ];
        });
    }

    public function down()
    {
        EsScheme::dropIfExists('boss');
    }

```

##### Now you can create your first document

[](#now-you-can-create-your-first-document)

```
$build = EsQuery::index('my_index');
$response = $build->create([
        'parent_id' => 1,
        'created_at' => '2022-02-26 23:44:00',
    ]);

```

##### Find your document

[](#find-your-document)

```
$build = EsQuery::index('my_index');
$response = $build->where('parent_id', 1)->first(); // Example 1
$response = $build->where('parent_id', '=', 1)->first(); // Example 2
$response = $build->where('parent_id', 1)->get(); // Example 3
$response = $build->where('created_at', '>=' '2022-02-26'))->get(); // Example 4

```

##### Performing an aggregation

[](#performing-an-aggregation)

```
$build = EsQuery::index('my_index');
$response = $build->where('parent_id', 1)->sum('price', 'total_price')->get(); // Use get() for aggregations

```

##### Delete your document

[](#delete-your-document)

```
$build = EsQuery::index('my_index');
$response = $build->where('parent_id', 1)->delete(); // Example 1 delete with conditions
$response = $build->delete(5); // Example 2 delete by ID

```

##### Delete your index

[](#delete-your-index)

```
$build = EsQuery::index('my_index');
$response = $build->deleteIndex();

```

##### How you can attach relation

[](#how-you-can-attach-relation)

```
$build = EsQuery::index('my_index');
$response = $build->with('category', 'id', 'group_id')->get();

OR

$build = EsQuery::index('my_index');
$response = $build->with('category', 'id', 'group_id', function (QueryBuilder $query) {
    return $query->where('is_active', 1);
})->with('boss', 'id', 'boss_id', function (QueryBuilder $query) {
    return $query->where('is_active', 1);
})->get();

```

#### INDEX

[](#index)

\[x\] Create
\[x\] Delete
\[x\] Update mapping
\[x\] Exists
\[x\] Skip

#### DOCUMENT

[](#document)

\[x\] Create
\[x\] Create Many
\[x\] Update
\[x\] Delete by ID
\[x\] Delete by Query

#### TYPE SEARCH

[](#type-search)

\[x\] **FIRST** (with/without conditions)
\[x\] **GET** (with/without conditions)
\[x\] **PAGINATION** (with/without conditions)
\[x\] **AGGREGATION** MAX / MIN / SUM / AVG / COUNT
\[x\] **LIMIT**
\[x\] **GROUP BY**
\[x\] **GROUP BY DATE**

#### CONDITIONS

[](#conditions)

\[x\] where
\[x\] whereIn
\[x\] whereExists
\[x\] whereNotExists
\[x\] whereMissing
\[x\] between
\[x\] orderBy

#### ADDITIONAL

[](#additional)

\[x\] with
\[x\] reset query after get/first/paginate

#### ELASTIC SEARCH

[](#elastic-search)

Site:
Version: 8.1

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

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

Total

17

Last Release

1415d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/203483dacaa229cdffe458fcad421eb5d3f592fa9a0256de34d4803f4befd1e7?d=identicon)[jeffleyd](/maintainers/jeffleyd)

---

Top Contributors

[![jeffleyd](https://avatars.githubusercontent.com/u/45333690?v=4)](https://github.com/jeffleyd "jeffleyd (29 commits)")

---

Tags

laravelelastic searchelastic search eloquentelastic search laravellaravel elastic search

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jeffleyd-esquery/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M682](/packages/barryvdh-laravel-ide-helper)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M106](/packages/laravel-cashier)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k49.4M479](/packages/laravel-scout)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8703.0M17](/packages/yajra-laravel-oci8)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)

PHPackages © 2026

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