问题
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.
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.
Delete the original index.
DELETE /original_index
- Create the index with same name as original index and with changed mapping.
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