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

张开发
2026/4/14 12:34:00 15 分钟阅读

分享文章

记录一次ES索引迁移报错:1.两边索引参数不一致2.分析器与存储属性有冲突
背景由于第一次迁移的时候源端es中有三个索引没有迁移到目标端es源端es为华为云产品目标端es为自建保持版本一致。后期业务运行过程中发现全文检索的时候会用到这三个索引导致查不出原来的数据。所以需要重新将这三个索引迁移过来并将目标端新生成的索引中的数据进行合并。过程开始使用esm工具迁移通过查看日志发现错误# 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:[ftype.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 [defaut1l],typeil eso -ano!yent-except iona feasonaepper 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:2210x4fbmain.main() /Users/medcl/go/src/github.com/medcl/esm/main.go:406 0x30c5问题分析在使用ESM工具更新索引 core_we的映射(mapping)但遇到了字段映射冲突。具体来说1.目标索引中已存在字段opinion字段已经存在于索引中参数不兼容store参数当前为 true尝试改为 false不允许 analyzer分析器当前为 index_ansj尝试改为 default不允许ES限制Elasticsearch不允许修改已有字段的某些映射参数包括store参数 analyzer分析器 字段数据类型等解决方案1.创建新索引在同步源端数据的时候指定新索引 ./esm-linux-amd64-shttps://192.168.37.152:9200-dhttp://192.168.37.138:9200-xcore_we-ycore_we_new-muser:password-nuser:password-w10-b10--sliced_scroll_size10--buffer_count100000--copy_settings--copy_mappings--refresh2.reindex,重建索引将目标端已经存在的索引数据复制到新生成的索引中。同一集群curl-uuser:password-XPOSThttp://192.168.37.138:9200/_reindex?prettywait_for_completiontrue-HContent-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个文档都成功创建没有错误所以这个重新索引操作是成功的。3.查看数据总数是否增加curl-uuser:password-XGEThttp://192.168.37.138:9200/core_we_new/_count4.删除旧的索引curl-XDELETE-uuser:password http://192.168.37.138:9200/core_we5.给新的索引创建别名为删除的索引名字curl-uuser:password-XPUThttp://192.168.37.138:9200/core_we_new/_alias/core_we最后问题解决注意期间也对比过原索引和目标索引的这个mapping配置curl -X GET localhost:9200/source_index/_mapping?pretty source_mapping.json

更多文章