PHPackages                             opsource/queryadapter - 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. [Database &amp; ORM](/categories/database)
4. /
5. opsource/queryadapter

ActiveLibrary[Database &amp; ORM](/categories/database)

opsource/queryadapter
=====================

Revolutionize your Laravel query management with Laravel Query Adapter! Our adapter package includes multiple query executioners, including Elasticsearch and Eloquent, to help you efficiently run your Laravel queries. Say goodbye to query management headaches and hello to seamless query execution with Laravel Query Adapter. ies.

1.0.3(1y ago)65051MITPHPPHP &gt;=8.1.0CI failing

Since Dec 2Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/vahidaghazadeh/QuaryAdapter)[ Packagist](https://packagist.org/packages/opsource/queryadapter)[ Docs](https://github.com/vahidaghazadeh/queryadapter)[ RSS](/packages/opsource-queryadapter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (7)Versions (4)Used By (0)

Here’s an optimized version of your document:

---

QueryAdapter
============

[](#queryadapter)

QueryAdapter is a powerful Laravel package that provides an intuitive abstraction layer for interacting with Elasticsearch indices. It includes a set of query builders designed for searching, aggregating, and suggesting data, while offering essential utilities for efficient index management. This package enables developers to work with Elasticsearch in a structured and efficient way, eliminating the complexity of low-level queries.

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

[](#installation)

To get started, install the package via Composer:

```
composer require opsource/query-adapter
```

Usage
-----

[](#usage)

### Setting Up

[](#setting-up)

Before using the QueryAdapter package, ensure that your Elasticsearch client is properly configured. The package relies on `ElasticClient` to manage all Elasticsearch communications, ensuring smooth data indexing and retrieval.

### Interacting with Indices

[](#interacting-with-indices)

The `InteractsWithIndex` trait offers powerful methods to manage and query Elasticsearch indices efficiently.

#### Bulk Insert

[](#bulk-insert)

Insert multiple documents into an Elasticsearch index in a single operation for improved performance:

```
$data = [
    ['index' => ['_id' => 1]],
    ['name' => 'Product A', 'price' => 100],
    ['index' => ['_id' => 2]],
    ['name' => 'Product B', 'price' => 200],
];

$result = $this->bulk($data);
```

#### Fetch Index Information

[](#fetch-index-information)

Retrieve detailed information about a specific index, including settings and mappings:

```
$indexInfo = $this->catIndices('my_index');
```

#### Delete an Index

[](#delete-an-index)

Remove an index when it is no longer needed:

```
$result = $this->indicesDelete('my_index');
```

#### Create a New Index with Custom Settings

[](#create-a-new-index-with-custom-settings)

Define and create a new Elasticsearch index with custom settings:

```
$settings = [
    'settings' => [
        'number_of_shards' => 1,
        'number_of_replicas' => 1
    ]
];

$result = $this->indicesIndex('my_new_index', $settings);
```

#### Refresh an Index

[](#refresh-an-index)

Make recent operations visible to search queries:

```
$result = $this->indicesRefresh();
```

### Querying Data

[](#querying-data)

QueryAdapter simplifies querying with its builder-based approach.

#### Search Query

[](#search-query)

Perform a basic search query:

```
$query = $this->query()->match('name', 'Product A')->get();
```

#### Index Class Example

[](#index-class-example)

Create an index class similar to an Eloquent model:

```
use Ensi\LaravelElasticQuery\ElasticIndex;

class ProductsIndex extends ElasticIndex
{
    protected string $name = 'test_products';
    protected string $indicator = 'product_id';
}
```

Set a unique document attribute name for `$indicator`, which is used as an additional sort in `search_after`.

#### Query Example

[](#query-example)

Perform a search with complex filters and sorting:

```
$searchQuery = ProductsIndex::queryEngine();

$hits = $searchQuery
             ->where('rating', '>=', 5)
             ->whereDoesntHave('offers', fn(BoolQuery $queryEngine) => $queryEngine->where('seller_id', 10)->where('active', false))
             ->sortBy('rating', 'desc')
             ->sortByNested('offers', fn(SortableQuery $queryEngine) => $queryEngine->where('active', true)->sortBy('price', mode: 'min'))
             ->take(25)
             ->get();
```

### Filtering

[](#filtering)

```
$searchQuery->where('field', 'value');
$searchQuery->where('field', '>', 'value'); // Operators: `=`, `!=`, `>`, `=`, `whereNot('field', 'value'); // Equivalent to `where('field', '!=', 'value')`
$searchQuery->whereIn('field', ['value1', 'value2']);
$searchQuery->whereNotIn('field', ['value1', 'value2']);
$searchQuery->whereNull('field');
$searchQuery->whereNotNull('field');
```

### Nested Queries

[](#nested-queries)

```
$searchQuery->whereHas('nested_field', fn(BoolQuery $subQuery) => $subQuery->where('field_in_nested', 'value'));
$searchQuery->whereDoesntHave('nested_field', function (BoolQuery $subQuery) {
    $subQuery->whereHas('nested_field', fn(BoolQuery $subQuery2) => $subQuery2->whereNot('field', 'value'));
});
```

`nested_field` must have `nested` type. Subqueries can only use subdocument fields.

### Full-Text Search

[](#full-text-search)

```
$searchQuery->whereMatch('field_one', 'queryEngine string');
$searchQuery->whereMultiMatch(['field_one^3', 'field_two'], 'queryEngine string', MatchType::MOST_FIELDS);
```

### Sorting

[](#sorting)

```
$searchQuery->sortBy('field', SortOrder::DESC, SortMode::MAX, MissingValuesMode::FIRST);
$searchQuery->sortByNested('nested_field', fn(SortableQuery $subQuery) => $subQuery->where('field_in_nested', 'value')->sortBy('field'));
```

Use dedicated sort methods for each sort type:

```
$searchQuery->minSortBy('field', 'asc');
$searchQuery->maxSortBy('field', 'asc');
$searchQuery->avgSortBy('field', 'asc');
$searchQuery->sumSortBy('field', 'asc');
$searchQuery->medianSortBy('field', 'asc');
```

### Pagination

[](#pagination)

#### Offset Pagination

[](#offset-pagination)

```
$page = $searchQuery->paginate(15, 45);
```

#### Cursor Pagination

[](#cursor-pagination)

```
$page = $searchQuery->cursorPaginate(10);
$pageNext = $searchQuery->cursorPaginate(10, $page->next);
```

### Aggregation

[](#aggregation)

Create aggregation queries:

```
$aggQuery = ProductsIndex::aggregate();

$aggs = $aggQuery
            ->where('active', true)
            ->terms('codes', 'code')
            ->count('product_count', 'product_id')
            ->nested(
                'offers',
                fn(AggregationsBuilder $builder) => $builder->where('seller_id', 10)->minmax('price', 'price')
            );
```

#### Aggregate Types

[](#aggregate-types)

```
$aggQuery->terms('agg_name', 'field', 25);
$aggQuery->minmax('agg_name', 'field');
$aggQuery->count('agg_name', 'field');
```

### Suggesting

[](#suggesting)

Create suggest queries for autocomplete or typo correction:

```
$sugQuery = ProductsIndex::suggest();
$suggests = $sugQuery->phrase('suggestName', 'name.trigram')->text('glves')->size(1)->shardSize(3)->get();
```

### Suggester Types

[](#suggester-types)

Term Suggester:

```
$aggQuery->term('suggestName', 'name.trigram')->text('glves')->get();
```

Phrase Suggester:

```
$aggQuery->phrase('suggestName', 'name.trigram')->text('glves')->get();
```

CLI Commands
------------

[](#cli-commands)

### `engine:make`

[](#enginemake)

Generates various engine components:

```
php artisan engine:make {type} [--model=] [--module=] [--index=] [--force] [--facade] [--job]
```

### `engine:make-facade`

[](#enginemake-facade)

Generates a facade for a search engine model.

### `engine:make-directive`

[](#enginemake-directive)

Creates a directive class for a search engine model.

Query Log
---------

[](#query-log)

Enable query logging to track executed queries:

```
ElasticQuery::enableQueryLog();
$records = ElasticQuery::getQueryLog();
ElasticQuery::disableQueryLog();
```

Environment Variables
---------------------

[](#environment-variables)

Configure the following environment variables:

```
ELASTICSEARCH_HOSTS=https://localhost:9200
ELASTICSEARCH_RETRIES=2
ELASTICSEARCH_USERNAME=admin
ELASTICSEARCH_PASSWORD=admin
ELASTICSEARCH_SSL_VERIFICATION=true
```

Elasticsearch Version Compatibility
-----------------------------------

[](#elasticsearch-version-compatibility)

Separate releases are created for Elasticsearch 7 and 8. Development for each version occurs in corresponding branches.

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

[](#contributing)

See [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

License
-------

[](#license)

MIT License. See [LICENSE.md](LICENSE.md) for more information.

---

This version improves readability and structure while maintaining clarity. It consolidates sections, removes redundancy, and ensures consistency throughout the document.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance46

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

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

Total

2

Last Release

473d ago

### Community

Maintainers

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

---

Top Contributors

[![vahidaghazadeh](https://avatars.githubusercontent.com/u/20494854?v=4)](https://github.com/vahidaghazadeh "vahidaghazadeh (38 commits)")

---

Tags

elasticsearchlaravelquery-builderlaravelelasticsearcheloquentqueryadapterquery builderquery-executionerquery-builder-commonquery-builder-elasticsearchquery-builder-eloquentquery-builder-rabbitmqquery-builder-common-helper

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/opsource-queryadapter/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11120.2M21](/packages/anourvalar-eloquent-serialize)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[matchory/elasticsearch

The missing elasticsearch ORM for Laravel!

3059.0k](/packages/matchory-elasticsearch)[designmynight/laravel-elasticsearch

Use Elasticsearch as a database in Laravel to retrieve Eloquent models and perform aggregations.

3038.6k](/packages/designmynight-laravel-elasticsearch)[brokerexchange/elasticbuilder

Query Builder for Elasticsearch.

111.1k](/packages/brokerexchange-elasticbuilder)

PHPackages © 2026

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