PHPackages                             earc/data-elasticsearch - 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. [Framework](/categories/framework)
4. /
5. earc/data-elasticsearch

ActiveLibrary[Framework](/categories/framework)

earc/data-elasticsearch
=======================

eArc - the explicit architecture framework - data elasticsearch component

0.0(5y ago)0161MITPHPPHP ^8.0

Since Apr 10Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Koudela/eArc-data-elasticsearch)[ Packagist](https://packagist.org/packages/earc/data-elasticsearch)[ RSS](/packages/earc-data-elasticsearch/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (1)

eArc-data-elasticsearch
=======================

[](#earc-data-elasticsearch)

Elasticsearch-bridge for the [earc/data](https://github.com/Koudela/eArc-data)persistence handler.

table of contents
-----------------

[](#table-of-contents)

- [installation](#installation)
- [basic usage](#basic-usage)
    - [bootstrap](#bootstrap)
    - [initialize index](#initialize-index)
    - [search](#search)
    - [enhanced syntax](#enhanced-syntax)
        - [range](#range)
        - [match](#match)
        - [text](#text)
        - [exists](#exists)
        - [\_id](#_id)
        - [embedded entity](#embedded-entity)
        - [embedded entity collection (nested)](#embedded-entity-collection-nested)
        - [joins](#joins)
        - [raw query](#raw-query)
        - [raw search body](#raw-search-body)
- [advanced usage](#advanced-usage)
    - [index name](#index-name)
    - [entity whitelist and blacklist](#entity-whitelist-and-blacklist)
    - [extend the elasticsearch bridge](#extend-the-elasticsearch-bridge)
- [releases](#releases)
    - [release 0.0](#release-00)

installation
------------

[](#installation)

Install the earc data elasticsearch library via composer.

```
$ composer require earc/data-elasticsearch
```

basic usage
-----------

[](#basic-usage)

### bootstrap

[](#bootstrap)

Initialize the earc/data package.

```
use eArc\Data\Initializer;

Initializer::init();
```

If your elasticsearch server is *not* located at `localhost:9200` or you need to authenticate, you have to configure it.

```
use eArc\DataElasticsearch\ParameterInterface;

$hosts = ['https://user:pass@elasticsearch.my-server.com:32775'];

di_set_param(ParameterInterface::CLIENT_HOSTS, $hosts);
```

Then register the earc/data-elasticsearch bridge.

```
use eArc\Data\ParameterInterface;
use eArc\DataElasticsearch\ElasticsearchDataBridge;

di_tag(ParameterInterface::TAG_ON_PERSIST, ElasticsearchDataBridge::class);
di_tag(ParameterInterface::TAG_ON_REMOVE, ElasticsearchDataBridge::class);
di_tag(ParameterInterface::TAG_ON_FIND, ElasticsearchDataBridge::class);
```

Now your entities will be indexed and removed from the index automatically. You are ready to search your earc/data entities via elasticsearch.

### initialize index

[](#initialize-index)

If you have persisted entities before installing the earc/data-elasticsearch bridge, you can use `IndexService::rebuildIndex()` to index the entities that are in your data-store already.

```
use eArc\DataElasticsearch\IndexService;

di_get(IndexService::class)->rebuildIndex([
    // list of your entity classes
]);
```

This has to be done only once. New entities and updates are indexed automatically.

### search

[](#search)

To search is very straight forward.

```
$primaryKeys = data_find(MyUserEntity::class, ['name' => ['Max', 'Moritz'], 'age' => 21]);
$userEntities = data_load_batch(MyUserEntity::class, $primaryKeys);
```

This would find all entities of the `MyUserEntitiy` class with a `name` property of `Max` or `Moritz` and an `age` property of `21`.

If you don't need the primary keys `data_find_entities` is shorter.

```
$userEntities = data_find_entities(MyUserEntity::class, ['name' => ['Max', 'Moritz'], 'age' => 21]);
```

To find all existing primary keys use the empty array.

```
$allUserPrimaryKeys = data_find(MyUserEntity::class, []);
```

### enhanced syntax

[](#enhanced-syntax)

earc/data-elasticsearch supports more than the complete earc/data `data_find` syntax. From the support for ranges and full text search to every elasticsearch query possible. This one size fits all approach is simple to start with, but as hard as the elasticsearch dsl to master.

#### range

[](#range)

The use of the range is done via a `..range` postfix.

```
data_find(MyUserEntity::class, ['age..range' => ['>' => 18]]);
```

This gives an open range above 18.

Closed ranges are possible too.

```
data_find(MyUserEntity::class, ['lastLogin..range' => ['>=' => '2021-01-01', ' 'eur']);
```

#### exists

[](#exists)

Elasticsearch does not know `null` values. Instead of `IS NOT NULL` you can check if a property exists, which is in most cases the same.

```
data_find(Price::class, ['currency..exists' => null]);
```

Or check if a property does not exist, which is similar to `IS NULL`.

```
data_find(Price::class, ['currency..exists_not' => null]);
```

#### \_id

[](#_id)

The getter `getPrimaryKey()` is used as elasticsearch document id. Thus, you can use the property `_id` to test against one or more primary keys.

```
data_find(MyUserEntity::class, ['_id' => ['1', '2', '392']]);
```

#### embedded entity

[](#embedded-entity)

To query embedded entities you can use the dot syntax.

```
data_find(MyUserEntity::class, [
    'login.email' => 'kai@email.com',
    'login.password' => 'l9TFoW5549',
]);
```

#### embedded entity collection (nested)

[](#embedded-entity-collection-nested)

Embedded entity collections have two properties `_entityName` and `_items`. `_items`invoke a nested query.

```
data_find(MyUserEntity::class, [
    'group._entityName' => Permission::class,
    'group._items' => [
        'name' => ['admin', 'moderator'],
        'active' => true,
    ],
]);
```

#### joins

[](#joins)

Elasticsearch does not know joins, but they can be realized via two separate queries.

```
$colorCategories = data_find(AttributeCategory::class, ['name..match' => ['colour', 'color']]);
$colors = data_find(Attribute::class, [
    'attributeCategory' => $colorCategories,
    'name..match' => ['blue', 'green', 'violet'],
]);
```

This works for one-to-one and many-to-one relations.

If your joined entity uses a collection e.g. the join represents a one-to-many or a many-to-many relation, then you have to use the `.items` embedded syntax.

```
$colors = data_find(Attribute::class, ['name..match' => ['white']]);
$colorCategories = data_find(AttributeCategory::class, ['attributes.items' => $colors]);
```

#### raw query

[](#raw-query)

You can always call upon the raw power of the elasticsearch dsl via the `.raw` postfix.

```
data_find(Price::class, [
    'offerStartDate.raw' => ['bool' => ['must' => [
        ['exists' => ['field' => 'offerStartDate']],
        ['range' => ['offerStartDate' => ['lte' => 'now']]],
    ]]],
]);
```

#### raw search body

[](#raw-search-body)

To write the complete search in the elasticsearch dsl use the `.raw_body` key.

```
data_find(Price::class, [
    '.raw_body' => [
        'query' => [
            'constant_score' => [
                'filter' => [
                    'bool' => [
                        'must' => [
                            ['exists' => ['field' => 'offerStartDate']],
                            ['range' => ['offerStartDate' => ['lte' => 'now']]],
                        ],
                    ],
                ],
            ],
        ],
    ],
]);
```

advanced usage
--------------

[](#advanced-usage)

### index name

[](#index-name)

The indices of the entities are named `earc-data-` plus the lowercase version of the fully qualified class name where the backslash `\\` is replaced by the minus sign `-`. The `earc-data` prefix can be configured.

```
use eArc\DataElasticsearch\ParameterInterface;

di_set_param(ParameterInterface::INDEX_PREFIX, 'my-index-prefix');
```

### entity whitelist and blacklist

[](#entity-whitelist-and-blacklist)

All entities are indexed by default. This can be changed via whitelisting or blacklisting.

```
use eArc\DataElasticsearch\ParameterInterface;
use eArc\DataElasticsearchTests\Entities\BlacklistedEntity;

di_set_param(ParameterInterface::WHITELIST, [
    // list of entity class names
    BlacklistedEntity::class => true,
    // ...
]);
```

Only the entities on the whitelist will be indexed.

```
use eArc\DataElasticsearch\ParameterInterface;

di_set_param(ParameterInterface::BLACKLIST, [
    // list of entity class names
    Attribute::class => true,
    // ...
]);
```

All but the entities on the blacklist will be indexed.

If black- and whitelist is configured the whitelist is used only.

### extend the elasticsearch bridge

[](#extend-the-elasticsearch-bridge)

To extend the elasticsearch bridge just decorate one of its classes.

```
use eArc\DataElasticsearch\DocumentFactory;

di_decorate(DocumentFactory::class, MyDocumentFactory::class);
```

Since there are only three classes (`DocumentFactory`, `ElasticsearchDataBridge` and `IndexService`) copy and pasting them into your project is a reasonable option.

releases
--------

[](#releases)

### release 0.0

[](#release-00)

- the first official release
- php ^8.0 support
- elasticsearch ^7.0 support

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

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

Unknown

Total

1

Last Release

1911d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b7308f2797252cace014cfec12c1b5978c1bf5608be78d7a188ff690192959f3?d=identicon)[Thomas Koudela](/maintainers/Thomas%20Koudela)

---

Top Contributors

[![Koudela](https://avatars.githubusercontent.com/u/21366492?v=4)](https://github.com/Koudela "Koudela (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/earc-data-elasticsearch/health.svg)

```
[![Health](https://phpackages.com/badges/earc-data-elasticsearch/health.svg)](https://phpackages.com/packages/earc-data-elasticsearch)
```

###  Alternatives

[bagisto/bagisto

Bagisto Laravel E-Commerce

27.6k172.1k9](/packages/bagisto-bagisto)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[magento/community-edition

Magento 2 (Open Source)

12.2k53.6k13](/packages/magento-community-edition)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[shopware/shopware

Shopware 5 is an open source e-commerce software made in Germany

1.3k748.3k35](/packages/shopware-shopware)[shopsys/framework

Core of Shopsys Platform - open source framework for building large, scalable, fast-growing e-commerce projects based on Symfony

25225.3k36](/packages/shopsys-framework)

PHPackages © 2026

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