PHPackages                             erichard/elasticsearch-query-builder - 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. erichard/elasticsearch-query-builder

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

erichard/elasticsearch-query-builder
====================================

Create elastic search query with a fluent interface

3.3.0(2mo ago)39366.7k—9.3%20[2 issues](https://github.com/erichard/elasticsearch-query-builder/issues)1MITPHPPHP &gt;=8.0CI failing

Since Feb 7Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/erichard/elasticsearch-query-builder)[ Packagist](https://packagist.org/packages/erichard/elasticsearch-query-builder)[ RSS](/packages/erichard-elasticsearch-query-builder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (12)Versions (16)Used By (1)

ElasticSearch Query Builder
===========================

[](#elasticsearch-query-builder)

[![img](https://camo.githubusercontent.com/96e40f6ccd34124c20d376beadaa363c117bfeeac1b62ce20eadecccf10627de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2d382d677265656e)](https://camo.githubusercontent.com/96e40f6ccd34124c20d376beadaa363c117bfeeac1b62ce20eadecccf10627de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2d382d677265656e)[![php](https://camo.githubusercontent.com/e7db701747863b44d71c99ff3ea0441ddfd7a95f374f47f4d01df8212f25b5e8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e302d627269676874677265656e)](https://camo.githubusercontent.com/e7db701747863b44d71c99ff3ea0441ddfd7a95f374f47f4d01df8212f25b5e8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e302d627269676874677265656e)

This is a PHP library which helps you build query for an ElasticSearch client by using a fluent interface.

WARNING: This branch contains the next 3.x release. Check the [corresponding issue](https://github.com/erichard/elasticsearch-query-builder/issues/7) for the roadmap.

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

[](#installation)

```
composer require erichard/elasticsearch-query-builder "^3.0@beta"
```

Usage
-----

[](#usage)

```
use Erichard\ElasticQueryBuilder\QueryBuilder;
use Erichard\ElasticQueryBuilder\Aggregation\Aggregation;
use Erichard\ElasticQueryBuilder\Filter\Filter;

$qb = new QueryBuilder();

$qb
    ->setIndex('app')
    ->setSize(10)
;

// Add an aggregation
$qb->addAggregation(Aggregation::terms('agg_name', 'my_field'));
$qb->addAggregation(Aggregation::terms('agg_name_same_as_field'));

// Set query
$qb->setQuery(Query::terms('field', 'value'));

// I am using a client from elasticsearch/elasticsearch here
$results = $client->search($qb->build());
```

with PHP 8.1 you can use named arguments like this:

```
$query = new BoolQuery(must: [
    new RangeQuery(
        field: 'price',
        gte: 100
    ),
    new RangeQuery(
        field: 'stock',
        gte: 10
    ),
]);
```

or with the factory

```
$query = Query::bool(must: [
    Query::range(
        field: 'price',
        gte: 100
    ),
    Query::range(
        field: 'stock',
        gte: 10
    ),
]);
```

Contribution
------------

[](#contribution)

- Use PHPCS fixer and PHPStan
    - `composer lint`
- Update tests (PHPUnit)
    - `composer test`

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance85

Actively maintained with recent releases

Popularity49

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity76

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

Recently: every ~35 days

Total

15

Last Release

74d ago

Major Versions

v1.0.1 → v2.0.02018-03-09

2.x-dev → 3.0.0-beta2022-04-26

PHP version history (2 changes)v1.0.0PHP &gt;=7.0

3.0.0-betaPHP &gt;=8.0

### Community

Maintainers

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

---

Top Contributors

[![erichard](https://avatars.githubusercontent.com/u/651041?v=4)](https://github.com/erichard "erichard (37 commits)")[![jacbac](https://avatars.githubusercontent.com/u/2450942?v=4)](https://github.com/jacbac "jacbac (10 commits)")[![xsuchy09](https://avatars.githubusercontent.com/u/1107359?v=4)](https://github.com/xsuchy09 "xsuchy09 (8 commits)")[![Ilyes512](https://avatars.githubusercontent.com/u/2445415?v=4)](https://github.com/Ilyes512 "Ilyes512 (7 commits)")[![pionl](https://avatars.githubusercontent.com/u/1878831?v=4)](https://github.com/pionl "pionl (6 commits)")[![igoooor](https://avatars.githubusercontent.com/u/1036285?v=4)](https://github.com/igoooor "igoooor (5 commits)")[![janaculenova](https://avatars.githubusercontent.com/u/50296122?v=4)](https://github.com/janaculenova "janaculenova (4 commits)")[![mahdi-masa](https://avatars.githubusercontent.com/u/149302991?v=4)](https://github.com/mahdi-masa "mahdi-masa (3 commits)")[![wucdbm](https://avatars.githubusercontent.com/u/1559022?v=4)](https://github.com/wucdbm "wucdbm (3 commits)")[![thrashzone13](https://avatars.githubusercontent.com/u/50789773?v=4)](https://github.com/thrashzone13 "thrashzone13 (1 commits)")[![CraftLogan](https://avatars.githubusercontent.com/u/10950466?v=4)](https://github.com/CraftLogan "CraftLogan (1 commits)")

---

Tags

elasticsearchphpquerybuilder

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/erichard-elasticsearch-query-builder/health.svg)

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

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15224.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

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

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[shyim/opensearch-php-dsl

OpenSearch/Elasticsearch DSL library

175.9M9](/packages/shyim-opensearch-php-dsl)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)

PHPackages © 2026

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