您的位置:首页 > 其它

Elasticsearch创建索引

2016-09-04 23:13 288 查看
<?php
namespace CronBundle\Command\Elasticsearch;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use Elasticsearch\ClientBuilder;

/**
* command name : app/console elasticsearch:create:index
*/
class CreateIndexCommand extends Command
{
public function __construct()
{
parent::__construct();
}

protected function configure()
{
$this
->setName('elasticsearch:create:index')
->setDescription('')
->addOption(
'yell',
null,
InputOption::VALUE_NONE,
'If set, the task will yell in uppercase letters'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$client = ClientBuilder::create()->build();
$params = [
'index' => 'caishen_index',
'body'  => [
'settings' => [
'number_of_replicas' => 0,
],
'mappings' => [
'default_type' => [
'properties' => [
'name'     => [
'type'  => 'string',
'analyzer' => 'ik'
],
'name_pinyin' => [
'type' => 'string',
'analyzer' => 'pinyin_ngram_analyzer'
],
'keywords' => [
'type' => 'string'
]
],
],
],
],
];

$client->indices()->create($params);
$output->writeln('create user account successfully');
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: