PHPackages                             spameri/elastic-query - 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. [API Development](/categories/api)
4. /
5. spameri/elastic-query

ActiveLibrary[API Development](/categories/api)

spameri/elastic-query
=====================

Objects instead of arrays for querying to ElasticSearch.

v2.0.0(3w ago)644.6k↑59.5%4[1 issues](https://github.com/Spameri/ElasticQuery/issues)1PHPPHP &gt;=8.2

Since Oct 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Spameri/ElasticQuery)[ Packagist](https://packagist.org/packages/spameri/elastic-query)[ RSS](/packages/spameri-elastic-query/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (10)Versions (39)Used By (1)

ElasticQuery
============

[](#elasticquery)

A PHP library that converts Elasticsearch query DSL into strongly-typed PHP objects. Instead of building queries as arrays, use type-safe classes that mirror the Elasticsearch documentation.

Features
--------

[](#features)

- **Type-safe queries** — full-text, term-level, compound, geo, nested, joining, vector (knn / sparse\_vector / semantic), span queries, and rule queries
- **Aggregations** — metric (min, max, avg, stats, weighted\_avg, top\_hits, top\_metrics, t\_test, geo\_line, …), bucket (terms, histogram, date\_histogram, range, filter, filters, composite with typed sources, ip\_prefix, time\_series, …), pipeline (cumulative\_*, bucket\_*, normalize, serial\_diff, inference, …)
- **Function scoring** — field value factor, weight, random, decay (gauss / linear / exp), script\_score; score\_mode + boost\_mode
- **Sort** — field, geo-distance, script-based, with nested sort (filter / max\_children / recursive)
- **Highlight** — per-field config (type, fragment\_size, boundary scanner, encoder, fragmenter, highlight\_query, matched\_fields, no\_match\_size, order, phrase\_limit, …)
- **Search options** — `_source`, `track_total_hits`, `search_after`, `pit`, `collapse`, `rescore`, `suggest` (term / phrase / completion), `runtime_mappings`, `script_fields`, `docvalue_fields`, `stored_fields`, `terminate_after`, `timeout`, `profile`, `stats`, `ext`
- **Response mapping** — automatic mapping of Elasticsearch responses (including composite/named buckets, IP/date range buckets) to typed objects
- **Index mapping** — index settings, analyzers, tokenizers, filters

See [CHANGELOG.md](CHANGELOG.md) for the full list of types and arguments added in v2.

Requirements
------------

[](#requirements)

- PHP 8.2 or higher

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

[](#installation)

Install via [Composer](http://getcomposer.org/):

```
composer require spameri/elastic-query
```

Quick Start
-----------

[](#quick-start)

```
use Spameri\ElasticQuery\ElasticQuery;
use Spameri\ElasticQuery\Query\ElasticMatch;
use Spameri\ElasticQuery\Query\Term;

// Create a query
$query = new ElasticQuery();

// Add a must query (AND condition)
$query->addMustQuery(new ElasticMatch('title', 'Elasticsearch'));

// Add a filter (cached, no scoring)
$query->addFilter(new Term('status', 'published'));

// Set pagination
$query->options()->changeSize(10);
$query->options()->changeFrom(0);

// Convert to array for Elasticsearch client
$body = $query->toArray();
```

Documentation
-------------

[](#documentation)

Learn more in the [documentation](https://github.com/Spameri/ElasticQuery/tree/master/doc):

- [Usage](https://github.com/Spameri/ElasticQuery/tree/master/doc/01-usage.md) - Integration examples
- [Query Objects](https://github.com/Spameri/ElasticQuery/tree/master/doc/02-query-objects.md) - All query types
- [Aggregation Objects](https://github.com/Spameri/ElasticQuery/tree/master/doc/03-aggregation-objects.md) - Aggregation types
- [Result Objects](https://github.com/Spameri/ElasticQuery/tree/master/doc/04-result-objects.md) - Response mapping
- [Options &amp; Sorting](https://github.com/Spameri/ElasticQuery/tree/master/doc/05-options.md) - Pagination, sorting, scroll
- [Highlight &amp; Function Score](https://github.com/Spameri/ElasticQuery/tree/master/doc/06-highlight-function-score.md) - Highlighting and custom scoring
- [Mapping &amp; Settings](https://github.com/Spameri/ElasticQuery/tree/master/doc/07-mapping-settings.md) - Index configuration

License
-------

[](#license)

MIT

###  Health Score

61

—

FairBetter than 98% of packages

Maintenance90

Actively maintained with recent releases

Popularity35

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 98% 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 ~77 days

Recently: every ~182 days

Total

37

Last Release

24d ago

Major Versions

v0.6.0-beta → v1.0.0-alpha2020-09-20

v1.0.1 → v2.0.0-alpha2024-06-09

PHP version history (3 changes)v0.1.0PHP &gt;=7.1

v1.0.0-alpha.11PHP &gt;=7.4

v2.0.0-alphaPHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/114232067?v=4)[VBoss](/maintainers/VBoss)[@Vboss](https://github.com/Vboss)

---

Top Contributors

[![Spamercz](https://avatars.githubusercontent.com/u/1753937?v=4)](https://github.com/Spamercz "Spamercz (195 commits)")[![AloisJasa](https://avatars.githubusercontent.com/u/17596051?v=4)](https://github.com/AloisJasa "AloisJasa (2 commits)")[![Jakub-Fajkus](https://avatars.githubusercontent.com/u/13538235?v=4)](https://github.com/Jakub-Fajkus "Jakub-Fajkus (1 commits)")[![pechondra](https://avatars.githubusercontent.com/u/21057847?v=4)](https://github.com/pechondra "pechondra (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/spameri-elastic-query/health.svg)

```
[![Health](https://phpackages.com/badges/spameri-elastic-query/health.svg)](https://phpackages.com/packages/spameri-elastic-query)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k15](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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