ElasticSearch - How to make a 1-to-1 copy of an existing index

家住魔仙堡 提交于 2019-12-08 11:46:34

问题


I'm using Elasticsearch 2.3.3 and trying to make an exact copy of an existing index. (using the reindex plugin bundled with Elasticsearch installation)

The problem is that the data is copied but settings such as the mapping and the analyzer are left out.

What is the best way to make an exact copy of an existing index, including all of its settings?

My main goal is to create a copy, change the copy and only if all went well switch an alias to the copy. (Zero downtime backup and restore)


回答1:


In my opinion, the best way to achieve this would be to leverage index templates. Index templates allow you to store a specification of your index, including settings (hence analyzers) and mappings. Then whenever you create a new index which matches your template, ES will create the index for you using the settings and mappings present in the template.

So, first create an index template called index_template with the template pattern myindex-*:

PUT /_template/index_template
{
  "template": "myindex-*",
  "settings": {
    ... your settings ...
  },
  "mappings": {
    "type1": {
      "properties": {
         ... your mapping ...
      }
    }
  }
}

What will happen next is that whenever you want to index a new document in any index whose name matches myindex-*, ES will use this template (+settings and mappings) to create the new index.

So say your current index is called myindex-1 and you want to reindex it into a new index called myindex-2. You'd send a reindex query like this one

POST /_reindex
{
  "source": {
    "index": "myindex-1"
  },
  "dest": {
    "index": "myindex-2"
  }
}

myindex-2 doesn't exist yet, but it will be created in the process using the settings and mappings of index_template because the name myindex-2 matches the myindex-* pattern.

Simple as that.




回答2:


The following seems to achieve exactly what I wanted:

Using Snapshot And Restore I was able to restore to a different index:

POST /_snapshot/index_backup/snapshot_1/_restore { "indices": "original_index", "ignore_unavailable": true, "include_global_state": false, "rename_pattern": "original_index", "rename_replacement": "replica_index" }

As far as I can currently tell, it has accomplished exactly what I needed. A 1-to-1 copy of my original index.

I also suspect this operation has better performance than re-indexing for my purposes.



来源:https://stackoverflow.com/questions/39274181/elasticsearch-how-to-make-a-1-to-1-copy-of-an-existing-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!