ES数据的删除与备份

背景

需要删除索引下满足指定条件的文档数据,并将删除的数据进行备份。

操作步骤

新建索引

该索引结构与映射关系与原索引一致

查看原索引设置

java 复制代码
GET /tb/_settings


结果:
{
  "tb" : {
    "settings" : {
      "index" : {
        "routing" : {
          "allocation" : {
            "include" : {
              "_tier_preference" : "data_content"
            }
          }
        },
        "number_of_shards" : "1",
        "provided_name" : "tb",
        "creation_date" : "1719220554972",
        "analysis" : {
          "normalizer" : {
            "CustomNormalizer" : {
              "filter" : [
                "lowercase",
                "asciifolding"
              ],
              "type" : "custom"
            }
          },
          "analyzer" : {
            "optimizeIK" : {
              "type" : "custom",
              "tokenizer" : "ik_max_word"
            }
          }
        },
        "number_of_replicas" : "1",
        "uuid" : "ovmNbNg7T6W98WcpqYfQwQ",
        "version" : {
          "created" : "7170799"
        }
      }
    }
  }
}

查看映射关系

java 复制代码
GET /tb/_mapping


结果:
{
  "tb" : {
    "mappings" : {
      "dynamic" : "true",
      "properties" : {
        "createTime" : {
          "type" : "long",
          "coerce" : false
        },
        "creator" : {
          "type" : "keyword"
        },
        "dbId" : {
          "type" : "keyword"
        },
        "fileName" : {
          "type" : "keyword"
        },
        "id" : {
          "type" : "keyword"
        },
        "isApproved" : {
          "type" : "keyword"
        },
        "modifiedTime" : {
          "type" : "long",
          "coerce" : false
        },
        "modifier" : {
          "type" : "keyword"
        },
        "note" : {
          "type" : "keyword"
        },
        "original" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword"
            },
            "normalizer" : {
              "type" : "keyword",
              "normalizer" : "CustomNormalizer"
            },
            "pattern" : {
              "type" : "text",
              "norms" : false,
              "analyzer" : "pattern"
            },
            "standard" : {
              "type" : "text",
              "norms" : false,
              "analyzer" : "standard"
            }
          },
          "norms" : false,
          "analyzer" : "optimizeIK"
        },
        "originalLang" : {
          "type" : "keyword"
        },
        "remark" : {
          "type" : "keyword"
        },
        "reviewer" : {
          "type" : "keyword"
        },
        "translation" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword"
            },
            "normalizer" : {
              "type" : "keyword",
              "normalizer" : "CustomNormalizer"
            },
            "pattern" : {
              "type" : "text",
              "norms" : false,
              "analyzer" : "pattern"
            },
            "standard" : {
              "type" : "text",
              "norms" : false,
              "analyzer" : "standard"
            }
          },
          "norms" : false,
          "analyzer" : "optimizeIK"
        },
        "translationLang" : {
          "type" : "keyword"
        }
      }
    }
  }
}

新建索引

java 复制代码
PUT /tb81901
{
  "settings" : {
      "index" : {
        "analysis" : {
          "normalizer" : {
            "CustomNormalizer" : {
              "filter" : [
                "lowercase",
                "asciifolding"
              ],
              "type" : "custom"
            }
          },
          "analyzer" : {
            "optimizeIK" : {
              "type" : "custom",
              "tokenizer" : "ik_max_word"
            }
          }
        },
        "number_of_shards" : "1",
        "number_of_replicas" : "1"
      }
    },
  "mappings": {
      "dynamic" : "true",
      "properties" : {
        "createTime" : {
          "type" : "long",
          "coerce" : false
        },
        "creator" : {
          "type" : "keyword"
        },
        "dbId" : {
          "type" : "keyword"
        },
        "fileName" : {
          "type" : "keyword"
        },
        "id" : {
          "type" : "keyword"
        },
        "isApproved" : {
          "type" : "keyword"
        },
        "modifiedTime" : {
          "type" : "long",
          "coerce" : false
        },
        "modifier" : {
          "type" : "keyword"
        },
        "note" : {
          "type" : "keyword"
        },
        "original" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword"
            },
            "normalizer" : {
              "type" : "keyword",
              "normalizer" : "CustomNormalizer"
            },
            "pattern" : {
              "type" : "text",
              "norms" : false,
              "analyzer" : "pattern"
            },
            "standard" : {
              "type" : "text",
              "norms" : false,
              "analyzer" : "standard"
            }
          },
          "norms" : false,
          "analyzer" : "optimizeIK"
        },
        "originalLang" : {
          "type" : "keyword"
        },
        "remark" : {
          "type" : "keyword"
        },
        "reviewer" : {
          "type" : "keyword"
        },
        "translation" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword"
            },
            "normalizer" : {
              "type" : "keyword",
              "normalizer" : "CustomNormalizer"
            },
            "pattern" : {
              "type" : "text",
              "norms" : false,
              "analyzer" : "pattern"
            },
            "standard" : {
              "type" : "text",
              "norms" : false,
              "analyzer" : "standard"
            }
          },
          "norms" : false,
          "analyzer" : "optimizeIK"
        },
        "translationLang" : {
          "type" : "keyword"
        }
      }
    }
}

迁移数据

迁移原索引中满足删除条件的文档数据

java 复制代码
POST /_reindex
{
  "source": {
    "index": "tb",
    "query": {
      "bool": {
        "must": [
          {
            "term": {
              "dbId": {
                "value": "270057"
              }
            }
          }
        ]
      }
    }
  },
  "dest": {
    "index": "tb81901"
  }
}

删除数据

删除原索引中满足删除条件的文档数据

java 复制代码
POST /tb/_delete_by_query
{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "dbId": [
              "270057"
            ]
          }
        }
      ]
    }
  }
}
相关推荐
B站计算机毕业设计超人20 分钟前
计算机毕业设计Python+大模型农产品价格预测 ARIMA自回归模型 农产品可视化 农产品爬虫 机器学习 深度学习 大数据毕业设计 Django Flask
大数据·爬虫·python·深度学习·机器学习·课程设计·数据可视化
Carl_奕然1 小时前
【大数据算法】MapReduce算法概述之:MapReduce基础模型
大数据·算法·mapreduce
csdn5659738501 小时前
Elasticsearch 重建索引 数据迁移
elasticsearch·数据迁移·重建索引
天幕繁星2 小时前
docker desktop es windows解决vm.max_map_count [65530] is too low 问题
windows·elasticsearch·docker·docker desktop
Elastic 中国社区官方博客2 小时前
Elasticsearch 8.16:适用于生产的混合对话搜索和创新的向量数据量化,其性能优于乘积量化 (PQ)
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
m1chiru2 小时前
Elasticsearch 实战应用:高效搜索与数据分析
elasticsearch
飞翔的佩奇2 小时前
ElasticSearch:使用dsl语句同时查询出最近2小时、最近1天、最近7天、最近30天的数量
大数据·elasticsearch·搜索引擎·dsl
2301_769006782 小时前
19名专家被通报批评!国家科技重大专项评审违规!
大数据·人工智能·科技·sci·期刊·ssci
Yz98763 小时前
Kafka面试题
大数据·分布式·zookeeper·kafka·big data
爱搞技术的猫猫7 小时前
实现API接口的自动化
大数据·运维·数据库·性能优化·自动化·产品经理·1024程序员节