记录一次ES索引迁移报错:1.两边索引参数不一致2.分析器与存储属性有冲突

背景

由于第一次迁移的时候源端es中有三个索引没有迁移到目标端es(源端es为华为云产品,目标端es为自建,保持版本一致)。后期业务运行过程中发现全文检索的时候会用到这三个索引,导致查不出原来的数据。所以需要重新将这三个索引迁移过来,并将目标端新生成的索引中的数据进行合并。
过程:

开始使用esm工具迁移,通过查看日志发现错误:

ini 复制代码
# tail -f nohup.out[04-0209:59:34][ERR][ buffer.go:67 ,String]http://192.168.32.138:9200/core_we/_mapping[04-0209:59:34][ERR][v7.go:220,UpdateIndexMapping]TO4-02 09:59:34] [ERR]「 v.9o:17 ,UpdateIndexMopping] server error: {"error":'"root- cause":[f"type"."ilLegal.argument-exception","re1son" :'"Mopper for [opinion] conflicts with existing mopper:'n\tCannot update parameter Istore] from true] to Ffalse n\tCannot updateparometer [analyzer] from [index-onsj] to [default7"}],"type"."illegal-argument-exception".,"reason":"Mopper for [opinion] conflicts with existing mapper:' n' tCannot update parameter [store] from [true] to [false] n\ tCannot update parameter [anal yzer] from [index ansj]lto [default]"},"status":400}
anic: server error: "error":{'root.cause":['"type"."illegal -argument-exception","reason"."Mapper for [opinion] conflicts with existi1g mopper: n' tCannot update parameter [store] from [true] to [false] n\ tCannot update parameter [analyzer] from Lindex ansj] to [defau't1"l],"type""il eso -ano!yent-except iona feason"a"epper for [ooi nion confl cts wn th exi sting mepper:'n tConmot update parameter I
goroutine 1 [running]:main.(*ESAPIV7).UpdateIndexMapping(OxcOc2526c80, {0xc080541e40, Ox7}, Oxc080562ab0)/Users/medcl/go/src/github.com/medcl/esm/v7.go:221+0x4fbmain.main()
/Users/medcl/go/src/github.com/medcl/esm/main.go:406 +0x30c5

问题分析:

在使用ESM工具更新索引 core_we的映射(mapping),但遇到了字段映射冲突。具体来说:

1.目标索引中已存在字段:opinion字段已经存在于索引中

参数不兼容:

bash 复制代码
store参数:当前为 true,尝试改为 false(不允许)
analyzer分析器:当前为 index_ansj,尝试改为 default(不允许)

ES限制:Elasticsearch不允许修改已有字段的某些映射参数,包括:

ini 复制代码
store参数
analyzer分析器
字段数据类型等

解决方案:

bash 复制代码
1.创建新索引,在同步源端数据的时候指定新索引
./esm-linux-amd64 -s https://192.168.37.152:9200 -d http://192.168.37.138:9200 -x "core_we" -y "core_we_new" -m user:password -n user:password -w 10 -b 10 --sliced_scroll_size=10 --buffer_count=100000 --copy_settings --copy_mappings --refresh

2.reindex,重建索引,将目标端已经存在的索引数据复制到新生成的索引中。(同一集群)
curl -u user:password -X POST "http://192.168.37.138:9200/_reindex?pretty&wait_for_completion=true" -H "Content-Type:application/json" -d '{"source": { "index": "core_we" }, "dest": { "index": "core_we_new" }, "conflicts": "proceed" }'

{
"took": 23,
"timed_out" : false,
"total" : 191,
"updated" : 0,
"created" : 191,
"deleted": 0,
"batches" : 1,
"version_conflicts" : 0,
"noops" : 0,
"retries": {
"bulk" : 0,
"search" : 0
},
"throttled_millis" : 0,
"requests_per_second" : -1.0,
"throttled_until_millis" : 0,
"failures": [ ]
}

返回解释:
took" : 23 → 整个操作耗时23毫秒。
"timed_out" : false → 操作没有超时。
"total" : 191 → 总共重新索引了191个文档。
"updated" : 0 → 没有文档被更新(因为目标索引是新的,所以都是创建)。
"created" : 191 → 成功创建了191个文档。
"deleted" : 0 → 没有删除文档。
"batches" : 1 → 操作被分成了1个批次执行。
"version_conflicts" : 0 → 版本冲突数为0。
"noops" : 0 → 没有跳过任何操作。
"retries" : { "bulk" : 0, "search" : 0 } → 重试次数为0。
"throttled_millis" : 0 → 没有因限流而暂停的毫秒数。
"requests_per_second" : -1.0 → 每秒请求数无限制(-1表示不限制)。
"throttled_until_millis" : 0 → 没有因限流而等待的时间。
"failures" : [ ] → 失败列表为空,表示没有失败。
从结果来看,所有191个文档都成功创建,没有错误,所以这个重新索引操作是成功的。
bash 复制代码
3.查看数据总数是否增加
curl -u user:password -X GET "http://192.168.37.138:9200/core_we_new/_count"
4.删除旧的索引
curl -XDELETE -u user:password  http://192.168.37.138:9200/core_we
5.给新的索引创建别名为删除的索引名字
curl -u user:password  -XPUT http://192.168.37.138:9200/core_we_new/_alias/core_we

最后问题解决

注意期间也对比过原索引和目标索引的这个mapping配置

ini 复制代码
curl -X GET "localhost:9200/source_index/_mapping?pretty" > source_mapping.json 
相关推荐
不会写DN3 小时前
Git 开发中最常用的命令与场景
大数据·git·elasticsearch
古城小栈3 小时前
Go 牵手 ES
elasticsearch·golang·iphone
不像程序员的程序媛4 小时前
es查询是否存在某个字段
java·前端·elasticsearch
Elastic 中国社区官方博客4 小时前
使用 OpenTelemetry 和 Elastic 的 ML 和 AI Ops 可观测性
大数据·人工智能·elasticsearch·搜索引擎·全文检索
尽兴-19 小时前
Elasticsearch 性能调优指南:写入、检索、聚合与缓存全链路优化
大数据·elasticsearch·缓存·性能优化·es 读写原理
deep_drink1 天前
1.2、Python 与编程基础:文件处理与常用库
开发语言·python·elasticsearch·llm
切糕师学AI1 天前
Elasticsearch 深度解析:从核心原理到开发者实战
大数据·elasticsearch·搜索引擎·分布式搜索分析引擎
卖报的大地主1 天前
Learn Claude Code Agent 开发 | 12、目录级隔离:Git Worktree实现多任务并行无冲突
大数据·git·elasticsearch
weixin_449290011 天前
Elasticsearch各版本特性对比
java·大数据·elasticsearch