PHPackages                             anyitsolutions/elastic-adapter - 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. anyitsolutions/elastic-adapter

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

anyitsolutions/elastic-adapter
==============================

Adapter for official PHP Elasticsearch client

1.2.1(5y ago)09.2k↓25%MITPHPPHP ^7.2

Since May 1Pushed 5y agoCompare

[ Source](https://github.com/anyitsolutions/elastic-adapter)[ Packagist](https://packagist.org/packages/anyitsolutions/elastic-adapter)[ RSS](/packages/anyitsolutions-elastic-adapter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (7)Used By (0)

Elastic Adapter
===============

[](#elastic-adapter)

[![Latest Stable Version](https://camo.githubusercontent.com/9b312211ef697d4386a516597eb7e456ff8ee4b62398a3fc19d1a7ef92334d1f/68747470733a2f2f706f7365722e707567782e6f72672f626162656e6b6f6976616e2f656c61737469632d616461707465722f762f737461626c65)](https://packagist.org/packages/babenkoivan/elastic-adapter)[![Total Downloads](https://camo.githubusercontent.com/71603452396c5437225fde1151e0cbec593906afe26434a0cbf6c0335a64b21a/68747470733a2f2f706f7365722e707567782e6f72672f626162656e6b6f6976616e2f656c61737469632d616461707465722f646f776e6c6f616473)](https://packagist.org/packages/babenkoivan/elastic-adapter)[![License](https://camo.githubusercontent.com/079303cc397e1668198e3d2b521bf6ac4274d5e887ad14b154a0f0969bd2a935/68747470733a2f2f706f7365722e707567782e6f72672f626162656e6b6f6976616e2f656c61737469632d616461707465722f6c6963656e7365)](https://packagist.org/packages/babenkoivan/elastic-adapter)[![Build Status](https://camo.githubusercontent.com/042ef2e265a92cd81425ce0379f00e5c35d0a904d770139430beb96cbd416b65/68747470733a2f2f7472617669732d63692e636f6d2f626162656e6b6f6976616e2f656c61737469632d616461707465722e7376673f266272616e63683d6d6173746572)](https://travis-ci.com/babenkoivan/elastic-adapter)[![Donate PayPal](https://camo.githubusercontent.com/0b8a275d67dfb2aa74ac299fa07b7fce95217f6620448d88cf05ff9e3653e9bf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f6e6174652d70617970616c2d626c7565)](https://paypal.me/babenkoi)[![Donate Amazon](https://camo.githubusercontent.com/d16fca9e126410f4f08f6e790ce431f6f3976a5c5d8ec0cd398ea7c217b5d511/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f6e6174652d616d617a6f6e2d626c61636b)](https://www.amazon.de/Amazon-de-e-Gift-Voucher-Various-Designs/dp/B07Q1JNC7R)

---

Elastic Adapter is an adapter for official PHP Elasticsearch client. It's designed to simplify basic index and document operations.

Contents
--------

[](#contents)

- [Compatibility](#compatibility)
- [Installation](#installation)
- [Index Management](#index-management)
- [Document Management](#document-management)

Compatibility
-------------

[](#compatibility)

The current version of Elastic Adapter has been tested with the following configuration:

- PHP 7.2-7.4
- Elasticsearch 7.x

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

[](#installation)

The library can be installed via Composer:

```
composer require babenkoivan/elastic-adapter
```

Index Management
----------------

[](#index-management)

`IndexManager` can be used to manipulate indices. It uses Elasticsearch client as a dependency, therefore you need to initiate the client before you create an `IndexManager` instance:

```
$client = \Elasticsearch\ClientBuilder::fromConfig([
  'hosts' => [
      'localhost:9200'
  ]
]);

$indexManager = new \ElasticAdapter\Indices\IndexManager($client);
```

The manager provides a list of useful methods, which are listed below.

### Create

[](#create)

Creates an index, either with the default settings and mapping:

```
$index = new \ElasticAdapter\Indices\Index('my_index');

$indexManager->create($index);
```

or configured accordingly to your needs:

```
$mapping = (new \ElasticAdapter\Indices\Mapping())
    ->text('title', [
        'boost' => 2,
    ])
    ->keyword('tag', [
        'null_value' => 'NULL'
    ])
    ->geoPoint('location');

$settings = (new \ElasticAdapter\Indices\Settings())
    ->index([
        'number_of_replicas' => 2,
        'refresh_interval' => -1
    ]);

$index = new \ElasticAdapter\Indices\Index('my_index', $mapping, $settings);

$indexManager->create($index);
```

### Drop

[](#drop)

Deletes an index:

```
$indexManager->drop('my_index');
```

### Put Mapping

[](#put-mapping)

Updates an index mapping:

```
$mapping = (new \ElasticAdapter\Indices\Mapping())
    ->text('title', [
        'boost' => 2,
    ])
    ->keyword('tag', [
        'null_value' => 'NULL'
    ])
    ->geoPoint('location');

$indexManager->putMapping('my_index', $mapping);
```

### Put Settings

[](#put-settings)

Updates an index settings:

```
$settings = (new \ElasticAdapter\Indices\Settings())
    ->analysis([
        'analyzer' => [
            'content' => [
                'type' => 'custom',
                'tokenizer' => 'whitespace'
            ]
        ]
    ]);

$indexManager->putSettings('my_index', $settings);
```

### Exists

[](#exists)

Checks if an index exists:

```
$indexManager->exists('my_index');
```

### Open

[](#open)

Opens an index:

```
$indexManager->open('my_index');
```

### Close

[](#close)

Closes an index:

```
$indexManager->close('my_index');
```

Document Management
-------------------

[](#document-management)

Similarly to `IndexManager`, the `DocumentManager` class also depends on Elasticsearch client:

```
$client = \Elasticsearch\ClientBuilder::fromConfig([
  'hosts' => [
      'localhost:9200'
  ]
]);

$documentManager = new \ElasticAdapter\Documents\DocumentManager($client);
```

### Index

[](#index)

Adds a document to an index:

```
$documents = [
    new ElasticAdapter\Documents\Document('1', ['title' => 'foo']),
    new ElasticAdapter\Documents\Document('2', ['title' => 'bar']),
];

$documentManager->index('my_index', $documents);
```

There is also an option to refresh index immediately:

```
$documentManager->index('my_index', $documents, true);
```

### Delete

[](#delete)

Removes a document from index:

```
$documents = [
    new ElasticAdapter\Documents\Document('1', ['title' => 'foo']),
    new ElasticAdapter\Documents\Document('2', ['title' => 'bar']),
];

$documentManager->delete('my_index', $documents);
```

If you want an index to be refreshed immediately pass `true` as the third argument:

```
$documentManager->delete('my_index', $documents, true);
```

You can also delete documents using query:

```
$documentManager->deleteByQuery('my_index', ['match_all' => new \stdClass()]);
```

### Search

[](#search)

Finds documents in an index:

```
$request = new \ElasticAdapter\Search\SearchRequest([
    'match' => [
        'message' => 'test'
    ]
]);

$request->setHighlight([
    'fields' => [
        'message' => [
            'type' => 'plain',
            'fragment_size' => 15,
            'number_of_fragments' => 3,
            'fragmenter' => 'simple'
        ]
    ]
]);

$request->setSuggest([
    'my_suggest' => [
        'text' => 'test',
        'term' => [
            'field' => 'message'
        ]
    ]
]);

$request->setSource(['message', 'post_date']);

$request->setCollapse([
    'field' => 'user'
]);

$request->setSort([
    ['post_date' => ['order' => 'asc']],
    '_score'
]);

$request->setFrom(0)->setSize(20);

$response = $documentManager->search('my_index', $request);

// total number of matched documents
$total = $response->getHitsTotal();

// corresponding hits
$hits = $response->getHits();

// document, highlight or raw representation of the hit
foreach ($hits as $hit) {
    $document = $hit->getDocument();
    $highlight = $hit->getHighlight();
    $raw = $hit->getRaw();
}

// suggestions
$suggestions = $response->getSuggestions();
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.4% 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 ~38 days

Total

5

Last Release

2045d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/705dc7b0129bffd2fa54b1abce650e491ef3b079a7bd4e9c5bd9c2f4c5427f8c?d=identicon)[anyitsolutions](/maintainers/anyitsolutions)

---

Top Contributors

[![babenkoivan](https://avatars.githubusercontent.com/u/25812954?v=4)](https://github.com/babenkoivan "babenkoivan (37 commits)")[![anyitsolutions](https://avatars.githubusercontent.com/u/21997863?v=4)](https://github.com/anyitsolutions "anyitsolutions (1 commits)")

---

Tags

phpclientelasticsearchadapterelastic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/anyitsolutions-elastic-adapter/health.svg)

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

###  Alternatives

[elasticsearch/elasticsearch

PHP Client for Elasticsearch

5.3k178.3M939](/packages/elasticsearch-elasticsearch)[babenkoivan/elastic-adapter

Adapter for official PHP Elasticsearch client

404.0M9](/packages/babenkoivan-elastic-adapter)[babenkoivan/elastic-client

The official PHP Elasticsearch client integrated with Laravel

544.0M6](/packages/babenkoivan-elastic-client)[babenkoivan/elastic-scout-driver

Elasticsearch driver for Laravel Scout

2773.8M5](/packages/babenkoivan-elastic-scout-driver)[babenkoivan/elastic-scout-driver-plus

Extension for Elastic Scout Driver

2862.8M1](/packages/babenkoivan-elastic-scout-driver-plus)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)

PHPackages © 2026

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