PHP code example of haridarshan / opensearch-client
1. Go to this page and download the library: Download haridarshan/opensearch-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// see OpenSearch\Laravel\Client\ClientBuilder for the referenceclassMyClientBuilderimplementsOpenSearch\Laravel\Client\ClientBuilderInterface{
publicfunctiondefault(): Client{
// should return a client instance for the default connection
}
publicfunctionconnection(string $name): Client{
// should return a client instance for the connection with the given name
}
}
namespaceApp\Console\Commands;
useOpenSearch\Client;
useOpenSearch\Laravel\Client\ClientBuilderInterface;
useIlluminate\Console\Command;
classCreateIndexextendsCommand{
protected $signature = 'create:index {name}';
protected $description = 'Creates an index';
publicfunctionhandle(ClientBuilderInterface $clientBuilder){
// get a client for the default connection
$client = $clientBuilder->default();
// get a client for the connection with name "write"
$client = $clientBuilder->connection('write');
$client->indices()->create([
'index' => $this->argument('name')
]);
}
}