Skip to content

DirectoryTree/OpenSearchClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenSearch Client

A Laravel integration for the official 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\ClientBuilderInterface from the container to build OpenSearch clients:

namespace App\Console\Commands;

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

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

    protected $description = 'Creates an index';

    public function handle(ClientBuilderInterface $clientBuilder): void
    {
        $client = $clientBuilder->default();

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

You can also resolve named connections:

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

About

OpenSearch PHP client integration for Laravel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors

Languages