Elasticsearch index fields 重命名

reindex數據複製,重索引

POST _reindex
{
  "source": { "index": "twitter" }, "dest": { "index": "new_twitter" } }

字段重命名

把flag重命名爲taghtml

POST _reindex
{
  "source": { "index": "test" }, "dest": { "index": "test2" }, "script": { "inline": "ctx._source.tag = ctx._source.remove(\"flag\")" } }

案例

描述

在數據錄入時,字段yxdm和字段jwzydm數據位置錯位了,如今須要將數據調換回來curl

方法

先複製數據索引到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做爲中間變量存儲交換的字段elasticsearch

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-elasticsearchide

相關文章
相關標籤/搜索