es索引数据复制并增加条件和修改目标数据值
es操作同一个索引里数据的复制语法复制数据:
POST _reindex
{
"source": {
"index": "source_index"
},
"dest": {
"index": "destination_index"
}
}
字段值修改:
POST source_index/_update_by_query
{
"script": {
"source": "ctx._source.field_name = 'new_value'"
},
"query": {
"match": {
"field_name": "old_value"
}
}
}可以通过在 source 中添加 query 来设置条件,只有满足条件的文档才会被复制到目标索引中。例如:
POST _reindex
{
"source": {
"index": "source_index",
"query": {
"match": {
"field_name": "value"
}
}
},
"dest": {
"index": "destination_index"
}
}上述代码将只复制 source_index 中 field_name 字段值为 value 的文档到 destination_index 中。
可以在复制数据时使用脚本来修改字段的值,将修改后的值写入目标索引中。例如:
POST _reindex
{
"source": {
"index": "source_index"
},
"dest": {
"index": "destination_index"
},
"script": {
"source": "ctx._source.field_name = 'new_value'"
}
}上述代码将复制 source_index 中的所有文档到 destination_index 中,并将其中的 field_name 字段值修改为 new_value。如果需要对特定的文档进行修改,可以在 source 中添加 query 条件来指定。
例:在同一个索引下复制并设置字段新值
POST _reindex
{
"source": {
"index": "source_index",
"query": {
"match": {
"field_name": "value"
}
}
},
"dest": {
"index": "source_index"
},
"script": {
"source": "ctx._source.field_name = 'new_value'"
}
}
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页:
[1]