PHPackages                             gbprod/elastica-specification - 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. gbprod/elastica-specification

AbandonedArchivedLibrary[API Development](/categories/api)

gbprod/elastica-specification
=============================

This library allows you to create Elastica queries using the Specification pattern

v2.1.0(8y ago)114.9k1MITPHPPHP ^7.0

Since Sep 4Pushed 8y ago2 watchersCompare

[ Source](https://github.com/gbprod/elastica-specification)[ Packagist](https://packagist.org/packages/gbprod/elastica-specification)[ RSS](/packages/gbprod-elastica-specification/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (3)Versions (12)Used By (1)

Elastica specification
======================

[](#elastica-specification)

[![Build Status](https://camo.githubusercontent.com/3bf104e904682106f06e40104eab47c7d7baa4356bb1d8a4936fef0364efb518/68747470733a2f2f7472617669732d63692e6f72672f676270726f642f656c6173746963612d73706563696669636174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gbprod/elastica-specification)[![codecov](https://camo.githubusercontent.com/094da988438ba7773dae354c4875a8a3bd93ea8f00bab2294bf4f98d553c0bb4/68747470733a2f2f636f6465636f762e696f2f67682f676270726f642f656c6173746963612d73706563696669636174696f6e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/gbprod/elastica-specification)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/504f923190c3abb3af411f8f1c8bcac7bc0756998743332d824629d82d957a19/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f676270726f642f656c6173746963612d73706563696669636174696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/gbprod/elastica-specification/?branch=master)[![Dependency Status](https://camo.githubusercontent.com/e228cee2eea8aa98f419600af1d69ae4f9c02364ebaf8fc4c2296fe1cee0bf4b/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3537346139626338636538643065303034313330643333302f62616467652e737667)](https://www.versioneye.com/user/projects/574a9bc8ce8d0e004130d330)

[![Latest Stable Version](https://camo.githubusercontent.com/0a0eea70b2e5fe85165397337f0d228bea9e31348bb61be6b1a3b9042238b4a0/68747470733a2f2f706f7365722e707567782e6f72672f676270726f642f656c6173746963612d73706563696669636174696f6e2f76657273696f6e)](https://packagist.org/packages/gbprod/elastica-specification)[![Total Downloads](https://camo.githubusercontent.com/0ad55db28d03a3520d4f46dc610b66fc80890e57e440780b27575376e9e8d649/68747470733a2f2f706f7365722e707567782e6f72672f676270726f642f656c6173746963612d73706563696669636174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/gbprod/elastica-specification)[![Latest Unstable Version](https://camo.githubusercontent.com/2434f357f2672dca5f40ca5717f86d31177ec1c19012e220d40055a714874ff5/68747470733a2f2f706f7365722e707567782e6f72672f676270726f642f656c6173746963612d73706563696669636174696f6e2f762f756e737461626c65)](https://packagist.org/packages/gbprod/elastica-specification)[![License](https://camo.githubusercontent.com/ad662d15b1ce2681e38c7372f0e6f33270b294a501f8e7978cd100097a0e5db1/68747470733a2f2f706f7365722e707567782e6f72672f676270726f642f656c6173746963612d73706563696669636174696f6e2f6c6963656e7365)](https://packagist.org/packages/gbprod/elastica-specification)

This library allows you to create Elastica queries using the [specification pattern](http://en.wikipedia.org/wiki/Specification_pattern).

Usage
-----

[](#usage)

You can write specifications using [gbprod/specification](https://github.com/gbprod/specification) library.

### Creates a elastica specification filter

[](#creates-a-elastica-specification-filter)

```
namespace GBProd\Acme\Elastica\SpecificationFactory;

use GBProd\ElasticaSpecification\QueryFactory\Factory;
use GBProd\Specification\Specification;
use Elastica\QueryBuilder;

class IsAvailableFactory implements Factory
{
    public function create(Specification $spec, QueryBuilder $qb)
    {
        return $qb->query()->bool()
            ->addMust(
                $qb->query()->term(['available' => "0"]),
            )
        ;
    }
}
```

### Configure

[](#configure)

```
$registry = new GBProd\ElasticaSpecification\Registry();
$qb = new \Elastica\QueryBuilder();

$handler = new GBProd\ElasticaSpecification\Handler($registry, $qb);
$handler->registerFactory(IsAvailable::class, new IsAvailableFactory());
$handler->registerFactory(StockGreaterThan::class, new StockGreaterThanFactory());
```

### Use it

[](#use-it)

```
$available = new IsAvailable();
$hightStock = new StockGreaterThan(4);

$availableWithLowStock = $available
    ->andX(
        $hightStock->not()
    )
;

$type = $this->elasticaClient
    ->getIndex('my_index')
    ->getType('my_type')
;

$query = $handler->handle($availableWithLowStock)

$results = $type->search($query);
```

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

[](#requirements)

- PHP 7.0+

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

[](#installation)

### Using composer

[](#using-composer)

```
composer require gbprod/elastica-specification
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

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

Recently: every ~101 days

Total

11

Last Release

3068d ago

Major Versions

v0.2.0 → v1.0-beta.02016-12-28

v1.1.0 → v2.0.02017-06-26

PHP version history (2 changes)v0.1.0PHP &gt;=5.6

v2.0.0PHP ^7.0

### Community

Maintainers

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

---

Top Contributors

[![gbprod](https://avatars.githubusercontent.com/u/3751019?v=4)](https://github.com/gbprod "gbprod (26 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gbprod-elastica-specification/health.svg)

```
[![Health](https://phpackages.com/badges/gbprod-elastica-specification/health.svg)](https://phpackages.com/packages/gbprod-elastica-specification)
```

###  Alternatives

[friendsofsymfony/elastica-bundle

Elasticsearch PHP integration for your Symfony project using Elastica

1.3k17.9M50](/packages/friendsofsymfony-elastica-bundle)[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)

PHPackages © 2026

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