<?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'); } }
Elasticsearch创建索引
最新推荐文章于 2024-04-27 09:48:32 发布