Mic*_*lis 3 elasticsearch reindex
https://www.elastic.co/blog/changing-mapping-with-zero-downtime/
我尝试使用本指南创建一个新索引,并在零停机时间内重新索引我的数据。
现在,我有一个名为“ photoshooter”的索引,并且按照以下步骤进行操作
1)使用新的映射创建新的索引“ photoshooter_v1” ...(完成)
2)创建别名...
curl -XPOST本地主机:9200 / _aliases -d'
{
"actions": [
{ "add": {
"alias": "photoshooter",
"index": "photoshooter_v1"
}}
]
}
Run Code Online (Sandbox Code Playgroud)
我得到这个错误...
{
"error": "InvalidAliasNameException[[photoshooter_v1] Invalid alias name [photoshooter], an index exists with the same name as the alias]",
"status": 400
}
Run Code Online (Sandbox Code Playgroud)
我想我失去了一些逻辑。
小智 6
可以说,如果我猜对了,您当前的索引名为“ photoshooter”。
现在,首先为此索引创建一个别名-确定
{
"actions": [
{ "add": {
"alias": "photoshooter_docs",
"index": "photoshooter"
}}
]
}
Run Code Online (Sandbox Code Playgroud)
测试- curl -XGET 'localhost:9200/photoshooter_docs/_search'
注意-现在,您将使用'photoshooter_docs'作为索引名称与您的索引进行交互,这实际上是'photoshooter'好的。
现在我们使用您的新映射创建一个新索引,假设我们将其命名为“ photoshooter_v2”,现在将“ photoshooter”索引数据复制到新索引(photoshooter_v2)
复制完所有数据后,只需将别名从以前的索引中删除到新索引-
curl -XPOST localhost:9200/_aliases -d '
{
"actions": [
{ "remove": {
"alias": "photoshooter_docs",
"index": "photoshooter"
}},
{ "add": {
"alias": "photoshooter_docs",
"index": "photoshooter_v2"
}}
]
}
Run Code Online (Sandbox Code Playgroud)
再次测试-> curl -XGET 'localhost:9200/photoshooter_docs/_search'
恭喜,您已更改了映射,而停机时间为零。
要复制数据,您可以使用这样的工具
https://github.com/mallocator/Elasticsearch-Exporter
Run Code Online (Sandbox Code Playgroud)
注意-此工具还会将映射从旧索引复制到新索引,而您可能不想这样做。以便您已阅读其文档或根据您的用途对其进行编辑。
谢谢
希望这可以帮助
| 归档时间: |
|
| 查看次数: |
5785 次 |
| 最近记录: |