ElasticSearch - 以零停机时间重新建立数据 [英] ElasticSearch - Reindexing your data with zero downtime

查看:1784
本文介绍了ElasticSearch - 以零停机时间重新建立数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://www.elastic.co/blog/changing -mapping-with-zero-stopime /



我试图创建一个新的索引,并用本指南以零停机时间重新索引我的数据。



现在我有一个名为photohooter的索引,我按照步骤



1)创建新索引photoshooter_v1与新的映射...(完成)



2)创建别名...



curl -XPOST localhost:9200 / _aliases -d'

  {
actions:[
{add:{
alias:photoshooter,
index:photoshooter_v1
}}
]
}

我收到此错误...

  {
error:InvalidAliasNameException [[photoshooter_v1]无效的别名[photoshooter],索引存在与别名相同的名称],
status :400
}

我觉得我输了一些逻辑..

解决方案

如果我猜对了,可以将您当前的索引命名为photohooter。



现在为此索引创建一个别名 - OK

  {
actions:[
{add:{
alias:photoshooter_docs,
index:photoshooter
}}
]
}

测试它 - curl -XGET'localhost:9200 / photoshooter_docs / _search'注意 - 现在,您将使用photoshooter_docs作为索引名称与您的索引进行交互,这实际上是photohooter。Ok。



现在我们用新的映射创建一个新索引,假设我们命名为'photoshooter_v2',将你的'photohooter'索引数据复制到新的索引(photoshooter_v2)



一旦您已经复制了所有的数据,只需
将上一个索引中的别名删除到新的索引 -

  curl -XPOST localhost:9200 / _aliases -d'
{
actions:[
{remove:{
alias:photoshooter_docs,
index:photoshooter
}},
{add:{
alias:photoshooter_docs b $ bindex:photoshooter_v2
}}
]
}

再次测试 - > curl -XGET'localhost:9200 / photoshooter_docs / _search'



恭喜您更改了您的映射,而无需停机。



要复制数据,您可以使用这样的工具

  https://github.com/mallocator/Elasticsearch-Exporter 

注 - 此工具还会将映射从旧索引复制到您可能不想做的新索引。所以您已阅读其文档或根据您的使用进行编辑。



感谢



希望这有助于


https://www.elastic.co/blog/changing-mapping-with-zero-downtime/

I try to create a new index and reindexing my data with zero downtime with this guide.

Now I have an index called "photoshooter" and I follow the steps

1) Create new index "photoshooter_v1" with the new mapping... (Done)

2) Create alias...

curl -XPOST localhost:9200/_aliases -d '

{
    "actions": [
        { "add": {
            "alias": "photoshooter",
            "index": "photoshooter_v1"
        }}
    ]
}

and I get this error...

{
    "error": "InvalidAliasNameException[[photoshooter_v1] Invalid alias name [photoshooter], an index exists with the same name as the alias]",
    "status": 400
}

I think I lose something with the logic..

解决方案

Lets say your current index is named as "photoshooter " if i am guessing it right ok.

Now Create a Alias for this index first - OK

     {
            "actions": [
                { "add": {
                    "alias": "photoshooter_docs",
                    "index": "photoshooter"
                }}
            ]
        }

test it - curl -XGET 'localhost:9200/photoshooter_docs/_search'

Note - now you will use 'photoshooter_docs' as index name to interact with your index which is actually 'photoshooter' Ok.

Now we create a new index with your new mapping let's say we name it 'photoshooter_v2' now copy your 'photoshooter' index data to new index(photoshooter_v2)

Once you have copied all your data now simply Remove the alias from previous index to new index -

      curl -XPOST localhost:9200/_aliases -d '
        {
            "actions": [
                { "remove": {
                    "alias": "photoshooter_docs",
                    "index": "photoshooter"
                }},
                { "add": {
                    "alias": "photoshooter_docs",
                    "index": "photoshooter_v2"
                }}
            ]
        }

test it again -> curl -XGET 'localhost:9200/photoshooter_docs/_search'

Congrats you have changed your mapping without zero downtime .

And to copy data you can use tools like this

    https://github.com/mallocator/Elasticsearch-Exporter 

Note - this tools also copies the mapping from old index to new index which you might don't want to do. So that you have read in its documentation or edit it according to your use .

Thanks

Hope this helps

这篇关于ElasticSearch - 以零停机时间重新建立数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆