Skip to content

Repository files navigation

OpenSearch Client

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:

namespaceApp\Console\Commands;
useDirectoryTree\OpenSearchClient\OpenSearchManager;
useIlluminate\Console\Command;
class CreateIndex extends Command
{
protected$signature = 'create:index {name}';
protected$description = 'Creates an index';
publicfunctionhandle(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:

useDirectoryTree\OpenSearchClient\Facades\OpenSearch;
$client = OpenSearch::connection('write');

Credits

This package builds on a lot of the foundation and prior work from Ivan Babenko and his Elasticsearch Laravel ecosystem packages.

We're grateful for the work he has shared with the Laravel community. If this package helps your work, consider supporting Ivan through GitHub Sponsors.

About

OpenSearch PHP client integration for Laravel

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages