reindex简单使用学习总结,总结了在一些场景中使用reindex做Elasticsearch数据迁移的方式。
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了reindex简单使用学习总结,总结了在一些场景中使用reindex做Elasticsearch数据迁移的方式。,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2429字,纯文字阅读大概需要4分钟。
内容图文
1.简单的reindex
source里是源index,dest里是目标索引。remote里必须是在新集群中加入了白名单的ip和port
POST _reindex
{
"source": {
"remote": {
"host": "http://ip:port"
},
"index": "index1"
},
"dest": {
"index": "index2"
}
}
2.只reindex目标索引中缺少的
op_type设置为create,只迁移目标索引中没有但老集群有的数据
POST _reindex
{
"source": {
"remote": {
"host": "http://ip:port"
},
"index": "index1"
},
"dest": {
"index": "index2",
"op_type": "create"
}
}
3.设置批次大小
通过设置size来实现,默认的size是1000
POST _reindex
{
"source": {
"remote": {
"host": "http://ip:port"
},
"index": "index1",
"size": 2000
},
"dest": {
"index": "index2"
}
}
4.遇到冲突继续
通过设置 “conflicts”: “proceed” 和 “op_type”: “create” 实现
POST _reindex
{
"conflicts": "proceed",
"source": {
"remote": {
"host": "http://ip:port"
},
"index": "index1"
},
"dest": {
"index": "index2",
"op_type": "create"
}
}
5.只reindex符合条件的数据
通过dsl查询实现,查出需要reindex的数据。
POST _reindex
{
"source": {
"remote": {
"host": "http://ip:port"
},
"index": "index1",
"query": {
"term": { "name": "zs" }
}
},
"dest": {
"index": "index2"
}
}
6.只reindex 源索引中的部分字段
通过 _source 指定要reindex的字段
POST _reindex
{
"source": {
"remote": {
"host": "http://ip:port"
},
"index": "index1",
"_source": [ "column1","column2" ]
},
"dest": {
"index": "index2"
}
}
7.屏蔽不想reindex的数据
使用 excludes 屏蔽不想reindex的字段
POST _reindex
{
"source": {
"remote": {
"host": "http://ip:port"
},
"index": "index1",
"excludes": [ "column1","column2" ]
},
"dest": {
"index": "index2"
}
}
8.用script脚本在reindex时做数据处理
通过painless实现。painless是es 5.x以后推出的一种简单,安全的脚本语言。也是es 5.x以后默认的脚本语言。
此实例时将boolean中的True转换为true.
POST _reindex
{
"source": {
"remote": {
"host": "http://ip:port"
},
"index": "index1"
},
"dest": {
"index": "index2"
},
"script": {
"inline": "if (ctx._source.auth != null) {ctx._source.column=ctx._source.column.toString().toLowerCase();} ",
"lang": "painless"
}
}
9.字段重新命名
同样是使用script,将name属性重命名为newName
POST _reindex
{
"source": {
"remote": {
"host": "http://ip:port"
},
"index": "index1"
},
"dest": {
"index": "index2"
},
"script": {
"inline": "ctx._source.newName = ctx._source.remove(\"name\")",
"lang": "painless"
}
}
10.客户端双写时
通过设置"conflicts":“proceed” 和 “version_type”: “external” 来保证保证version低的不覆盖
{
"conflicts":"proceed",
"source": {
"remote": {
"host": "http://ip:port"
},
"index": "index1"
},
"dest": {
"version_type": "external",
"index": "index2"
}
}
内容总结
以上是互联网集市为您收集整理的reindex简单使用学习总结,总结了在一些场景中使用reindex做Elasticsearch数据迁移的方式。全部内容,希望文章能够帮你解决reindex简单使用学习总结,总结了在一些场景中使用reindex做Elasticsearch数据迁移的方式。所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。