简体   繁体   English

Elasticsearch-重新索引相同的索引名称

[英]Elasticsearch--reindexing to the same index name

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 我一直在阅读关于stackoverflow

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 ' 我当前的地址是' http://地址到服务器:端口/群集名称/索引名称 '

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) 我希望能够重新索引旧数据,以便在我curl -XGET 'http://address-to-server:port/cluster-name/index-name'它将在新映射中提供旧数据(一些其他字段,一些已修改)

As my previous answer you can use reindexing plugins to perform the mapping change actions 作为我之前的回答,您可以使用重新索引插件来执行映射更改操作

https://github.com/codelibs/elasticsearch-reindexing 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 并且还要通过检查样本输入数据来确保您的新映射有效并且将采用您的旧数据

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 . 注意:您需要为此安装npm插件

Read this to install elasticsearch-reindex command. 阅读此内容以安装elasticsearch-reindex命令。

Hope this helps. 希望这可以帮助。

For those who are looking to run reindex script to update the same index. 对于那些正在寻找运行reindex脚本来更新相同索引的人。 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 ). 基本上,“重新索引到同一索引”是一种“通过查询更新”( https://www.elastic.co/guide/zh-CN/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 您可以使用与reindex相同的script子句,并将其应用于查询结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM