2020年3月10日 星期二

[elasticsearch] elasitcsearch reindex api query 特定條件並且加上欄位

[elasticsearch] elasitcsearch reindex   api query 特定條件並且加上欄位

怎麼使用 elasticsearch  的 reindex 功能query 特定條件資料並且加上新的欄位呢?
可以使用reindex api , query 加上 script ,來達成

POST _reindex
{
  "source": {
    "index": "data-2020-02-21",
    "size": 1000,
    "query": {
      "match": {
        "targetId": "1"
      }
    }
  },
  "dest": {
    "index": "data-2020-03-09"
  },
  "script": {
    "source": "ctx._source['myField'] = 0.5",
    "lang": "painless"
  }
}
查看 Tasks 的狀態
GET _tasks?detailed=true&actions=*reindex
怎麼取消 Tasks
POST _tasks/VLSt1CjMR3-MM0TLdEor9A:2945063561/_cancel

ref
Index Aliases | Elasticsearch Reference [6.8] | Elastic https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-aliases.html
"POST /_aliases
{
    "actions" : [
        { "remove" : { "index" : "test1", "alias" : "alias1" } },
        { "add" : { "index" : "test2", "alias" : "alias1" } }
    ]
}"
Reindex API | Elasticsearch Reference [7.6] | Elastic https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html

沒有留言:

張貼留言