PHPackages                             directorytree/opensearch-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. [API Development](/categories/api)
4. /
5. directorytree/opensearch-adapter

ActiveLibrary[API Development](/categories/api)

directorytree/opensearch-adapter
================================

A PHP adapter for the OpenSearch PHP client

v1.0.0(today)10MITPHPPHP ^8.2CI passing

Since Jun 22Pushed todayCompare

[ Source](https://github.com/DirectoryTree/OpenSearchAdapter)[ Packagist](https://packagist.org/packages/directorytree/opensearch-adapter)[ RSS](/packages/directorytree-opensearch-adapter/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (4)Versions (2)Used By (0)

OpenSearch Adapter
==================

[](#opensearch-adapter)

A PHP adapter for the [OpenSearch PHP client](https://github.com/opensearch-project/opensearch-php).

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

[](#installation)

Install the package with Composer:

```
composer require directorytree/opensearch-adapter
```

Creating Managers
-----------------

[](#creating-managers)

Create the adapter managers from an `OpenSearch\Client` instance:

```
use DirectoryTree\OpenSearchAdapter\Documents\DocumentManager;
use DirectoryTree\OpenSearchAdapter\Indices\IndexManager;
use OpenSearch\Client;

$documents = new DocumentManager($client);
$indices = new IndexManager($client);
```

Managing Indices
----------------

[](#managing-indices)

Use an index blueprint when you want fluent mapping and settings builders:

```
use DirectoryTree\OpenSearchAdapter\Indices\IndexBlueprint;
use DirectoryTree\OpenSearchAdapter\Indices\Mapping;
use DirectoryTree\OpenSearchAdapter\Indices\Settings;

$mapping = (new Mapping)
    ->keyword('id')
    ->text('title')
    ->object('author', [
        'properties' => [
            'name' => ['type' => 'text'],
        ],
    ]);

$settings = (new Settings)->index([
    'number_of_shards' => 1,
    'number_of_replicas' => 0,
    'refresh_interval' => '1s',
]);

$indices->create(new IndexBlueprint('books', $mapping, $settings));
```

Use `field()` for less common, custom, or newer OpenSearch field types:

```
$mapping = (new Mapping)->field('embedding', 'custom_vector', [
    'dimension' => 1536,
]);
```

Settings include top-level setters for common OpenSearch settings groups:

```
$settings = (new Settings)
    ->index([
        'number_of_shards' => 1,
        'number_of_replicas' => 0,
    ])
    ->analysis([
        'analyzer' => [
            'content' => [
                'type' => 'custom',
                'tokenizer' => 'whitespace',
            ],
        ],
    ])
    ->similarity([
        'default' => [
            'type' => 'BM25',
        ],
    ]);
```

Use `set()` for top-level settings groups that do not have a dedicated method:

```
$settings = (new Settings)
    ->set('custom_group', [
        'enabled' => true,
    ]);
```

Indexing Documents
------------------

[](#indexing-documents)

Documents contain the OpenSearch document ID and source payload:

```
use DirectoryTree\OpenSearchAdapter\Documents\Document;

$documents->index('books', [
    new Document('1', [
        'title' => 'The Hobbit',
    ]),
]);
```

Document routing values can be attached by document ID:

```
use DirectoryTree\OpenSearchAdapter\Documents\DocumentRouting;

$routing = DocumentRouting::make('1', 'tenant-1');

$documents->index('books', [
    new Document('1', [
        'title' => 'The Hobbit',
    ]),
], routing: $routing);
```

Searching Documents
-------------------

[](#searching-documents)

Build a search request with raw OpenSearch query fragments:

```
use DirectoryTree\OpenSearchAdapter\Search\SearchRequest;

$request = (new SearchRequest([
    'match' => [
        'title' => 'hobbit',
    ],
]))
    ->size(10)
    ->highlight([
        'fields' => [
            'title' => new stdClass,
        ],
    ]);

$response = $documents->search('books', $request);

$total = $response->total();

$hits = array_map(
    fn ($hit) => $hit->document()->source(),
    $response->hits(),
);
```

Aliases
-------

[](#aliases)

Aliases can include optional filters and routing values:

```
use DirectoryTree\OpenSearchAdapter\Indices\Alias;

$indices->putAlias('books', new Alias(
    'tenant-books',
    filter: [
        'term' => [
            'tenant_id' => 1,
        ],
    ],
    routing: 'tenant-1',
));

$aliases = $indices->getAliases('books');
```

Raw Responses
-------------

[](#raw-responses)

Search response objects expose the original OpenSearch payload through `raw()`:

```
$rawHit = $response->hits()[0]->raw();
$rawResponse = $response->raw();
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

0d ago

### Community

Maintainers

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

---

Top Contributors

[![stevebauman](https://avatars.githubusercontent.com/u/6421846?v=4)](https://github.com/stevebauman "stevebauman (33 commits)")

---

Tags

phpclientopensearchadapter

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/directorytree-opensearch-adapter/health.svg)

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

###  Alternatives

[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

46784.5k5](/packages/deepseek-php-deepseek-php-client)

PHPackages © 2026

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