PHP code example of tarfin-labs / elastic-aws-client

1. Go to this page and download the library: Download tarfin-labs/elastic-aws-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.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tarfin-labs / elastic-aws-client example snippets


return [
    'hosts' => [
        [
            'host'            => env('ELASTICSEARCH_HOST', 'localhost'),
            'port'            => env('ELASTICSEARCH_PORT', 9200),
            'scheme'          => env('ELASTICSEARCH_SCHEME', null),
            'user'            => env('ELASTICSEARCH_USER', null),
            'pass'            => env('ELASTICSEARCH_PASS', null),

            // AWS
            'aws'             => env('AWS_ELASTICSEARCH_ENABLED', false),
            'aws_region'      => env('AWS_DEFAULT_REGION', ''),
            'aws_key'         => env('AWS_ACCESS_KEY_ID', ''),
            'aws_secret'      => env('AWS_SECRET_ACCESS_KEY', ''),
            'aws_credentials' => null
        ],
    ],
    'sslVerification' => null,
    'retries' => null,
    'sniffOnStart' => false,
    'httpHandler' => null,
    'connectionPool' => null,
    'connectionSelector' => null,
    'serializer' => null,
    'connectionFactory' => null,
    'endpoint' => null,
    'namespaces' => [],
];

namespace App\Console\Commands;

use Elasticsearch\Client;
use Illuminate\Console\Command;

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

    protected $description = 'Creates an index';

    public function handle(Client $client)
    {
        $client->indices()->create([
            'index' => $this->argument('name')
        ]);
    }
}
bash
php artisan vendor:publish --provider="ElasticAwsClient\ServiceProvider"