directorytree/opensearch-client

A Laravel integration for the official OpenSearch PHP client

Maintainers

Package info

github.com/DirectoryTree/OpenSearchClient

pkg:composer/directorytree/opensearch-client

Statistics

Installs: 6

Dependents: 2

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2026-06-22 13:50 UTC

This package is auto-updated.

Last update: 2026-06-23 16:02:06 UTC


README

A Laravel integration for the OpenSearch PHP client.

Installation

Install the package with Composer:

composer require directorytree/opensearch-client

Configuration

Publish the configuration file:

php artisan vendor:publish --provider="DirectoryTree\OpenSearchClient\OpenSearchClientServiceProvider"

The published config/opensearch-client.php file defines the default connection and any named OpenSearch connections:

return [
    'default' => env('OPENSEARCH_CONNECTION', 'default'),

    'connections' => [
        'default' => [
            'base_uri' => env('OPENSEARCH_HOST', 'http://localhost:9200'),
        ],
    ],
];

Each connection is passed directly to OpenSearch\GuzzleClientFactory.

Usage

Resolve DirectoryTree\OpenSearchClient\OpenSearchManager from the container to access OpenSearch clients:

namespace App\Console\Commands;

use DirectoryTree\OpenSearchClient\OpenSearchManager;
use Illuminate\Console\Command;

class CreateIndex extends Command
{
    protected $signature = 'create:index {name}';

    protected $description = 'Creates an index';

    public function handle(OpenSearchManager $opensearch): void
    {
        $client = $opensearch->default();

        $client->indices()->create([
            'index' => $this->argument('name'),
        ]);
    }
}

You can also resolve named connections:

$client = $opensearch->connection('write');

You may also use the facade:

use DirectoryTree\OpenSearchClient\Facades\OpenSearch;

$client = OpenSearch::connection('write');