es-删除字段-实测

es字段一旦创建是无法删除的,本案的方案是复制新老索引的方法

一、背景

现有索引 index1,待删除字段field1和extendMap.field2,es版本6.3.2

二、步骤

1、删除index1中的filed1和extendMap.field2两个字段的数据

复制代码
POST index1/_update_by_query  
{
  "query":{
        "bool":{
            "must":[
                {
                    "exists":{
                        "field":"field1"
                    }
                }
            ]
        }
    },
 "script": "ctx._source.remove('field1')"
  }

POST index1/_update_by_query  
{
  "query":{
        "bool":{
            "must":[
                {
                    "exists":{
                        "field":"extendMap.field2"
                    }
                }
            ]
        }
    },
 "script": "ctx._source.extendMap.remove('field2')"
  }

2、新建index2,map中不要有上述待删除字段

3、拷贝index1到index2

复制代码
POST _reindex
{
    "source": {
        "index": "index1"
    },
    "dest": {
        "index": "index2"
    }
}

4、删除index1

复制代码
DELETE index1

5、新建index1,map中不要有上述待删除字段

6、拷贝index2到index1

复制代码
POST _reindex
{
    "source": {
        "index": "index2"
    },
    "dest": {
        "index": "index1"
    }
}

7、删除index2

复制代码
DELETE index2

完成

相关推荐
大大大大晴天1 小时前
从 HDFS 到对象存储:计算存储分离如何重塑云原生大数据底座
大数据
阿里云大数据AI技术2 小时前
Agentic Search 2.0:从单轮对话迈向企业级 AI 搜索自动驾驶Agent
人工智能·elasticsearch·agent
这个DBA有点耶2 小时前
2026年分布式数据库有哪些主流选择?先评估这5个维度再决定
数据库·分布式·dba
Elasticsearch5 小时前
你的 AI agent 需要一个不在场证明:Elastic 中 Agent Builder 的可观测性和审计追踪
elasticsearch
这个DBA有点耶5 小时前
从MySQL 5.7到8.0:JSON查询性能差在哪?虚拟列索引vs多值索引怎么选
数据库·mysql·架构
胡写代码5 小时前
数据库审计字段,别再每张表各写一套了——我统一成这 6 个字段
数据库
Elasticsearch8 小时前
仪表板活动日志:了解哪些 Kibana 仪表板会被使用
elasticsearch
SelectDB9 小时前
为什么 JSON 正在成为分析数据库新的竞争点?
数据库·json·agent
ClouGence10 小时前
开源数据库管理工具 CloudDM 4.2.0 发布,新增 GoldenDB、KingbaseES 等数据源
数据库·dba·devops
发霉的馒头10 小时前
ORA-00845: MEMORY_TARGET not supported on this system的解决方法
数据库