filipgolonka / elasticsearch-reindex-bundle
Elasticsearch重索引包
0.3.0
2017-06-06 12:02 UTC
Requires
- php: ~7.0
- elasticsearch/elasticsearch: ^2.0, <5.0
- symfony/config: ~2.8|~3.0
- symfony/console: ~2.8|~3.0
- symfony/expression-language: ~2.8|~3.0
- symfony/framework-bundle: ~2.8|~3.0
- symfony/http-kernel: ~2.8|~3.0
Requires (Dev)
- behat/behat: ^3.3
- phing/phing: ^2.16
- phpmd/phpmd: ^2.6
- phpspec/phpspec: ^3.4
- ralfmaxxx/phpcs_rules: 0.2.0-alpha
- ralfmaxxx/phpmd_variable_lifetime: ^0.1.0
- sebastian/phpcpd: ~2.0|~3.0
- squizlabs/php_codesniffer: ~2.5
This package is not auto-updated.
Last update: 2024-09-15 02:30:03 UTC
README
允许在零停机时间模式中重新索引数据。
它是如何工作的?
见https://elastic.ac.cn/blog/changing-mapping-with-zero-downtime
长话短说
- 创建新索引
- 用数据填充
- 将别名指向新索引
- 删除旧索引
您的应用程序必须使用别名名称,而不是直接使用索引名称。
需求
- elasticsearch/elasticsearch >=2.0, <5.0
- symfony/config
- PHP >7.0
安装
composer require filipgolonka/elasticsearch-reindex-bundle
- 将以下行添加到
app/AppKernel.php
$bundles = [
// ...
new FilipGolonka\ElasticsearchReindexBundle\FilipGolonkaElasticsearchReindexBundle(),
// ...
];
- 将配置选项添加到
app/config/config.yml
filip_golonka_elasticsearch_reindex:
alias_name: 'alias_name'
elasticsearch_client: 'elasticsearch.client'
index_name_template: 'my-index-%s'
index_type: my-type
mapping: '%elasticsearch_mapping%'
reindex_command_name: 'app.command.elastic_search.importer.all_to'
settings: '%elasticsearch_settings%'
其中: alias_name
- 应用程序使用的别名 elasticsearch_client
- DI容器ID,指向\Elasticsearch\Client
对象 index_name_template
- 创建新索引时使用的模板。它必须是sprintf模式,含有一个占位符(换句话说,只包含一个%s
) index_type
- 应用程序中使用的文档类型 mapping
- 新创建索引的Elasticsearch映射 reindex_command_name
- DI容器ID,指向\Symfony\Component\Console\Command\Command
对象。此命令必须接受一个且仅接受一个参数:index_name
。 settings
- 新创建索引的Elasticsearch设置
Elasticsearch映射和设置示例
parameters:
elasticsearch_mapping:
dynamic: "environment == 'dev' ? 'strict' : false"
properties:
id:
type: string
date:
type: date
gallery:
type: object
properties:
image:
type: string
elasticsearch_settings:
number_of_shards: 1,
number_of_replicas: 0,
analysis:
analyzer:
analyzer_keyword:
tokenizer: 'keyword'
filter: 'lowercase'
开发
添加您的功能,但在提交拉取请求之前,请确保您没有破坏代码质量。
首先 - 运行代码静态分析工具
bin/phing quality
其次 - 运行测试
bin/phing tests
在提交拉取请求之前,请确保您的代码已用PhpSpec和Behat测试覆盖。
如何在本地运行Behat?
Behat测试确保包逻辑与Elasticsearch连接正常工作,因此需要Elasticsearch URL来运行测试。如何做到这一点?
export ELASTICSEARCH_URL=https://:9200 && bin/behat