头图

一、参考

elasticsearch 学习系列目录——更新ing

二、示例

2.1 修改字段名称

修改字段名称,即先删除原来字段,赋值新字段

POST _reindex
{
  "source": {
    "index": "yztest"
  },
  "dest": {
    "index": "yztest1"
  },
  "script": {
    "lang": "painless", 
    "source": """
      for (item in params.updateFields){
        if (ctx._source.containsKey(item)){
          def newItem = "df_" + item;
          ctx['_source'][newItem] = ctx._source.remove(item);
        }
      }
    """,
    "params": {
      "updateFields": ["f1", "f2"]
    }
  }
}

2.2 查询 reindex任务执行

GET _tasks?actions=*reindex*

{
  "nodes" : {
    "111" : {
      "name" : "11111",
      "transport_address" : "127.0.0.1:9300",
      "host" : "127.0.0.1",
      "ip" : "127.0.0.1:9300",
      "roles" : [
        "ingest",
        "master",
        "data",
        "ml"
      ],
      "attributes" : {
        "ml.machine_memory" : "16655953920",
        "xpack.installed" : "true",
        "ml.max_open_jobs" : "20"
      },
      "tasks" : {
        "LrCxElELQGqRNI4tok60ug:225074201" : {
          "node" : "LrCxElELQGqRNI4tok60ug",
          "id" : 225074201,
          "type" : "transport",
          "action" : "indices:data/write/reindex",
          "start_time_in_millis" : 1624954354511,
          "running_time_in_nanos" : 438795513169,
          "cancellable" : true,
          "headers" : { }
        }
      }
    }
  }
}

一曲广陵散
76 声望21 粉丝

柴米油盐酱醋茶