您的位置:首页 > 文旅 > 旅游 > ES数据的删除与备份

ES数据的删除与备份

2024/12/23 9:42:24 来源:https://blog.csdn.net/NoviceZ/article/details/142355140  浏览:    关键词:ES数据的删除与备份

背景

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

操作步骤

新建索引

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

查看原索引设置

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"}}}}
}

 查看映射关系

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"}}}}
}

新建索引

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"}}}
}

迁移数据

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

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

删除数据

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

POST /tb/_delete_by_query
{"query": {"bool": {"must": [{"terms": {"dbId": ["270057"]}}]}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com