PHP code example of nexucis / es-index-helper
1. Go to this page and download the library: Download nexucis/es-index-helper 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/ */
nexucis / es-index-helper example snippets
use Elasticsearch\ClientBuilder;
use Nexucis\Elasticsearch\Helper\Nodowntime\IndexHelper;
$alias = "myindex";
$helper->createIndexByAlias($alias);
$alias= 'myindex';
$helper->deleteIndexByAlias($alias);
$alias = "myindex";
$mappings = [
'properties' => [
'first_name' => [
'type' => 'text',
'analyzer' => 'standard'
],
'age' => [
'type' => 'integer'
]
]
];
$helper->updateMappings($alias, $mappings, false, true, true, false);
$alias = "myindex";
$mappings = [
'my_type' => [
'properties' => [
'first_name' => [
'type' => 'text',
'analyzer' => 'standard'
],
'age' => [
'type' => 'integer'
]
]
]
];
$helper->updateMappings($alias, $mappings);
$alias = "myindex";
$settings =[
'number_of_shards' => 1,
'number_of_replicas' => 0,
'analysis' => [
'filter' => [
'shingle' => [
'type' => 'shingle'
]
],
'char_filter' => [
'pre_negs' => [
'type' => 'pattern_replace',
'pattern' => '(\\w+)\\s+((?i:never|no|nothing|nowhere|noone|none|not|havent|hasnt|hadnt|cant|couldnt|shouldnt|wont|wouldnt|dont|doesnt|didnt|isnt|arent|aint))\\b',
'replacement' => '~$1 $2'
],
'post_negs' => [
'type' => 'pattern_replace',
'pattern' => '\\b((?i:never|no|nothing|nowhere|noone|none|not|havent|hasnt|hadnt|cant|couldnt|shouldnt|wont|wouldnt|dont|doesnt|didnt|isnt|arent|aint))\\s+(\\w+)',
'replacement' => '$1 ~$2'
]
],
'analyzer' => [
'reuters' => [
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => ['lowercase', 'stop', 'kstem']
]
]
]
];
$helper->updateSettings($alias, $settings);
$alias= "myindex";
$type = 'test';
$id='randomId';
$body = [
'latinField' => 'Palatii dicto sciens venit contumaciter'
];
if($helper->addDocument($alias, $type, $body)){
$document = $helper->getDocument($alias, $type, $id);
// do something with this document
}
bash
php composer.phar install