PHP code example of ashkan-jafarzadeh / elastic-migrations
1. Go to this page and download the library: Download ashkan-jafarzadeh/elastic-migrations 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/ */
ashkan-jafarzadeh / elastic-migrations example snippets
Index::create('my-index');
Index::create('my-index', function (Mapping $mapping, Settings $settings) {
// to add a new field to the mapping use method name as a field type (in Camel Case),
// first argument as a field name and optional second argument for additional field parameters
$mapping->text('title', ['boost' => 2]);
$mapping->float('price');
// you can define a dynamic template as follows
$mapping->dynamicTemplate('my_template_name', [
'match_mapping_type' => 'long',
'mapping' => [
'type' => 'integer',
],
]);
// you can also change the index settings and the analysis configuration
$settings->index([
'number_of_replicas' => 2,
'refresh_interval' => -1
]);
$settings->analysis([
'analyzer' => [
'title' => [
'type' => 'custom',
'tokenizer' => 'whitespace'
]
]
]);
});
// you can use a modifier as shown above
Index::createIfNotExists('my-index', $modifier);
// or you can use raw mapping and settings
Index::createIfNotExistsRaw('my-index', $mapping, $settings);