Elasticsearch--reindexing to the same index name

六眼飞鱼酱① 提交于 2019-12-13 01:45:03

问题


I have several old indices which I'd like to change mapping of. Now I need to transform old mapping into new ones. I've been reading on stackoverflow like

This one

This one

and this one

But I don't think they're the exact answer to my question.

Many of those use a different index name, so operation is easier that way, but due to the setup, we use a more crude way of curl-ing the data, which requires the exact index name.

Now my question is: what's a good way to reindex an old index (or several indices) to new one

ex.

my current address would be 'http://address-to-server:port/cluster-name/index-name'

I want to be able to reindex the old data so that when i curl -XGET 'http://address-to-server:port/cluster-name/index-name' it'll give the the old data in new mapping (some additional fields, some modified)


回答1:


As my previous answer you can use reindexing plugins to perform the mapping change actions

https://github.com/codelibs/elasticsearch-reindexing

And also make sure that your new mapping is valid and will adopt your old data by checking sample input data




回答2:


Following method can be used to re-index the data.

  1. Transfer data from original index to some dummy index. You can use below command

    elasticsearch-reindex -f "http://localhost:9200/original_index/type/" -t "http://localhost:9200/dummy_index/type/"

    This command is to be used in terminal.

  2. Delete the original index. DELETE /original_index

  3. Create the index with same name as original index and with changed mapping.
  4. Move the data back from dummy index to original index

    elasticsearch-reindex -f "http://localhost:9200/dummy_index/type/" -t "http://localhost:9200/original_index/type/"

THis way you can restore your data with new mappings.

NOTE: You need to install npm plugin for this.

Read this to install elasticsearch-reindex command.

Hope this helps.




回答3:


For those who are looking to run reindex script to update the same index. Basically "reindexing to the same index" is an "update by query" (https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html). You can use the same script clause as with reindex and apply it to a query result



来源:https://stackoverflow.com/questions/35232606/elasticsearch-reindexing-to-the-same-index-name

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