Elasticsearch index fields 重命名
reindex数据复制,重索引
POST _reindex
{
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter"
}
}
字段重命名
把flag重命名为tag
POST _reindex
{
"source": {
"index": "test"
},
"dest": {
"index": "test2"
},
"script": {
"inline": "ctx._source.tag = ctx._source.remove(\"flag\")"
}
}
案例
描述
在数据录入时,字段yxdm和字段jwzydm数据位置错位了,现在需要将数据调换回来
方法
先复制数据索引到bak
curl -XPOST 'http://10.130.20.6:8200/_reindex' -d '{
"source": {
"index": "sugon_course_students_onduty_2017_05"
},
"dest": {
"index": "sugon_course_students_onduty_bak2017_05"
}
}'
删除原索引数据,并从bak索引重新录入到原索引
注意需要使用yxdm1作为中间变量存储交换的字段
curl -XPOST 'http://10.130.20.6:8200/_reindex' -d '{
"source": {
"index": "sugon_course_students_onduty_bak2017_05"
},
"dest": {
"index": "sugon_course_students_onduty_2017_05"
},
"script": {
"inline": "ctx._source.yxdm1 = ctx._source.remove(\"jwzydm\");ctx._source.jwzydm = ctx._source.remove(\"yxdm\");ctx._source.yxdm = ctx._source.remove(\"yxdm1\")"
}
}'
参考
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html http://stackoverflow.com/questions/40607350/renaming-fields-in-elasticsearch