PHPackages                             gskema/elasticsearch-query-dsl-php - 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. gskema/elasticsearch-query-dsl-php

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

gskema/elasticsearch-query-dsl-php
==================================

Feature complete, object oriented, composable, extendable Elasticsearch query DSL builder for PHP.

6.1.0(2y ago)716.6k↓23.1%1MITPHPPHP ^8.1

Since Apr 4Pushed 2y agoCompare

[ Source](https://github.com/gskema/elasticsearch-query-dsl-php)[ Packagist](https://packagist.org/packages/gskema/elasticsearch-query-dsl-php)[ Docs](https://github.com/gskema/elasticsearch-query-dsl-php)[ RSS](/packages/gskema-elasticsearch-query-dsl-php/feed)WikiDiscussions 6.x Synced 1mo ago

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

Elasticsearch Query DSL
=======================

[](#elasticsearch-query-dsl)

[![Latest Version on Packagist](https://camo.githubusercontent.com/20891bf486c44036de364cc7bc07df7c8b527fa2744acc6f7921e266ad010439/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67736b656d612f656c61737469637365617263682d71756572792d64736c2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gskema/elasticsearch-query-dsl-php)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/defec265469ecc92cafcfa51f5ba557b025547dcd51ed10cca8938f5f1ac17e2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f67736b656d612f656c61737469637365617263682d71756572792d64736c2d7068702f63692e796d6c3f6272616e63683d362e78)](https://github.com/gskema/elasticsearch-query-dsl-php/actions)[![Coverage Status](https://raw.githubusercontent.com/gskema/elasticsearch-query-dsl-php/image-data/coverage.svg)](https://github.com/gskema/elasticsearch-query-dsl-php/actions)[![Total Downloads](https://camo.githubusercontent.com/057c41ff652dbdc5f616c1eda34c3dd480de4e62cdddf4a1e738fdad92a3a863/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f67736b656d612f656c61737469637365617263682d71756572792d64736c2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gskema/elasticsearch-query-dsl-php)

Feature complete, object oriented, composable, extendable Elasticsearch query DSL builder for PHP.

Features
--------

[](#features)

- Dependency free
- Can be used with any PHP Elasticsearch client
- Fully interfaced, ready for custom classes and
- Explicit class and property naming, fully matches produced JSON and Elasticsearch docs
- All configuration options are listed inside classes, links to documentation
- Classes can be easily composed, extended
- Usage of setters/getters so that everything can be inlined and chained.
- Fully working `::__clone()` methods
- Extendable code: no usage of `private`, `final` or `readonly`
- Basic objects created on `__construct`, no unnecessary body build logic until `jsonSerialize()` is called

Versions
--------

[](#versions)

Most of the classes should be compatible with any Elasticsearch versions. If something is not compatible or not supported, `Raw*` or custom classes can be used.

Package versionElasticsearch version&gt;=6.0.0 &lt;7.0.0&gt;=6.0.0 &lt;7.0.0&gt;=5.0.0 &lt;6.0.0&gt;=5.0.0 &lt;6.0.0Because major version number follows Elasticsearch major version number, second number is reserved for breaking changes.

Install
-------

[](#install)

```
composer require gskema/elasticsearch-query-dsl-php 6.* # match your Elasticsearch version
```

Usage
-----

[](#usage)

```
$searchRequest = new SearchRequest();
$searchRequest->setOption('min_score', 3.5);
$searchRequest->setSize(10);
$searchRequest->setQuery(
    (new BoolMatcher())->addMustNot(new TermMatcher('field1', 'value1'))
);
$searchRequest->addStatGroup('stat_group_1');
$searchRequest->setAgg(
    'agg1',
    (new FilterAggregation(new MatchAllMatcher()))
        ->setAgg('agg2', TermsAggregation::fromField('field2', 'value2'))
);

(new ElasticsearchClient())->search($searchRequest->jsonSerialize());
```

All classes match naming in official Elasticsearch documentation. Each class has a list of possible configuration options listed above class using attributes:

```
#[Options([
    'flags' => 'ALL|ANYSTRING|COMPLEMENT|EMPTY|INTERSECTION|INTERVAL|NONE',
    'max_determinized_states' => 2000,
    ...
])]
class RegexpMatcher implements MultiTermMatcherInterface {}
```

Similarly, `SearchRequest` class also has possible URL parameters listed:

```
#[Parameters([
    'timeout' => '2s',
    'terminate_after' => 1,
    'max_concurrent_shard_requests' => 2,
    ...
])]
class SearchRequest implements SearchRequestInterface {}
```

Matcher?
--------

[](#matcher)

Request object that is received by Elasticsearch `/_search/` has many properties and sub-properties like `query`, `filter`, `post_filter`, etc.

To avoid convoluted expressions like

```
(new SearchRequest())->setQuery(
    (new BoolQuery()->addFilter(new TermQuery('x')
)->setPostFilter(new BoolQuery(...)))
```

keyword `matcher` was explicitly chosen.

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

[](#change-log)

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

Testing
-------

[](#testing)

```
./vendor/bin/phpunit
```

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

[](#contributing)

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

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity76

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

Recently: every ~478 days

Total

6

Last Release

840d ago

Major Versions

v5.0.1 → 6.0.02023-10-25

PHP version history (2 changes)v5.0.0PHP ^7.0

6.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/1be92883d9fa346a69808e9e7ec640f4584cce5ffbf9db72c9f6917b3d93992f?d=identicon)[gskema](/maintainers/gskema)

---

Top Contributors

[![gskema](https://avatars.githubusercontent.com/u/5542423?v=4)](https://github.com/gskema "gskema (95 commits)")

---

Tags

dslelasticsearchphpqueryelasticsearchqueryDSL

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/gskema-elasticsearch-query-dsl-php/health.svg)

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

###  Alternatives

[elasticsearch/elasticsearch

PHP Client for Elasticsearch

5.3k178.3M943](/packages/elasticsearch-elasticsearch)[netgen/query-translator

Query Translator is a search query translator with AST representation

2042.0M6](/packages/netgen-query-translator)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15224.3M65](/packages/opensearch-project-opensearch-php)[babenkoivan/elastic-scout-driver

Elasticsearch driver for Laravel Scout

2773.8M5](/packages/babenkoivan-elastic-scout-driver)[jsq/amazon-es-php

Support for using IAM authentication with the official Elasticsearch PHP client

9310.6M13](/packages/jsq-amazon-es-php)[babenkoivan/elastic-client

The official PHP Elasticsearch client integrated with Laravel

544.0M6](/packages/babenkoivan-elastic-client)

PHPackages © 2026

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