我有一个现有的具有以下文档结构的弹性搜索索引,没有routing_key
{
"_id",
"feild1"
"field2"
}
我需要将数据迁移到新的索引中。索引的结构保持不变,但增加了routing_key。路由键需要更新为“field1_field2”。是否有一个简单的 Kibana 脚本来将数据迁移到新索引?
简单的 painless 和弹性搜索的 reindex API 的组合可以用来实现这一点。
POST _reindex
{
"source": {
"index": "{old_index_name}",
"size": {batch_size}
},
"dest": {
"index": "{new_index_name}"
},
"script": {
"lang": "painless",
"inline": "if (ctx._source.participants.length > 0) {ctx._routing=ctx._source.field1+'-'+ctx._source.field2}"
}
}
让我们补上最新的查询
POST _reindex?wait_for_completion=false // async call - you can track query progress if your index is huge - do GET _tasks/{your taskId}
{
"source": {
"index": *source index name*
},
"dest": {
"index": *destination index name*
},
"script": {
"source": """
ctx._routing = ctx._source.field1+'-'+ctx._source.field2;
"""
}
}