ES删除索引字段

438 阅读1分钟

一、ES索引删除字段逻辑

案例:向test/test索引中新增createTime,createDate字段

PUT /test/test/_mapping
{
  "test" : {
    "mappings" : {
      "test" : {
        "properties" : {
          "id" : {
            "type" : "long"
          },
          "age" : {
            "type" : "long"
          },
          "userId" : {
            "type" : "long"
          }
        }
      }
    }
  }
}

1、新增新索引

PUT test01

2、重新索引数据

POST _reindex
{
   "source": {
     "index": "test"
   },
   "dest": {
     "index": "test01"
   },
  "script": {
    "source": "ctx._source.remove('age');ctx._source.remove('userId')"
  }

}

注:"source" 可以清理多个字段

3、删除旧索引

DELETE test

4、新增新索引

PUT test

5、重复第2步骤