PHP code example of cviebrock / laravel-elasticsearch-handlers
1. Go to this page and download the library: Download cviebrock/laravel-elasticsearch-handlers 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/ */
cviebrock / laravel-elasticsearch-handlers example snippets
'providers' => array(
...
'Cviebrock\LaravelElasticSearch\ServiceProvider',
'Cviebrock\LaravelElasticSearchHandlers\ServiceProvider',
)
return [
'connections' => [
'default' => [
'clientClass' => 'Cviebrock\LaravelElasticsearchHandlers\Client',
'handlers' => []
]
]
];
$client = Elasticsearch::connection('default');
return [
'defaultClass' => 'Cviebrock\LaravelElasticsearchHandlers\Client',
'connections' => [
'default' => [
'MyEnvironmentIndexPrefixHandler'
]
]
];
class MyEnvironmentIndexPrefixHandler extends Cviebrock\LaravelElasticsearchHandlers\Handlers\BaseHandler {
/**
* Auto-prefix the document index name with the current Laravel
* environment.
*
* @param array $parameters
* @return array
*/
public function handleIndex($parameters) {
if ($index = array_get($parameters, 'index')) {
$environment = mb_strtolower(preg_replace('/[^a-z0-9_\-]+/', '-', \App::environment()));
$parameters['index'] = trim($environment, '-') . '-_' . $index;
}
return $parameters;
}
}
$data = [
'index' => 'my-index',
'type' => 'my-doctype',
'body' => [
'content' => 'Lorem ipsum',
]
];
$return = Elasticsearch::index($data);
public function boot(\Cviebrock\LaravelElasticsearchHandlers\Client $client) {}
shell
php artisan vendor:publish cviebrock/laravel-elasticsearch-handlers
shell
cp vendor/cviebrock/laravel-elasticsearch-handlers/config/elasticsearch-handlers.php app/config/