记录一次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 
相关推荐
yunqiz6 小时前
ELK Stack生产环境部署指南:Filebeat + Elasticsearch + Logstash + Kibana
elk·elasticsearch
dongsdh1 天前
部署python
大数据·elasticsearch·搜索引擎
听到微笑1 天前
Elasticsearch 如何存储与检索海量向量
数据库·elasticsearch
知福致福1 天前
【技术复盘】Git 分支污染与提交污染事故排查与解法
大数据·git·elasticsearch
敲代码的嘎仔1 天前
互动问答系统实战:两级评论模型、ES 搜索集成、Caffeine 多级缓存全记录
java·开发语言·数据库·elasticsearch·缓存·mybatis·高并发
彧azz2 天前
Git 入门实操实例:从安装到远程仓库全流程
大数据·笔记·git·学习·elasticsearch
醉颜凉2 天前
Canal 与 Elasticsearch 实时同步:增量索引更新、删除处理与全量重建方案
elasticsearch·canal·数据同步·增量更新·全量重建
无风听海2 天前
深入解析 Elasticsearch 的 match_phrase_prefix与 match_bool_prefix
大数据·elasticsearch·mybatis
天天喝旺仔2 天前
Elasticsearch 全文检索实战:Lucene 倒排索引与 NoSQL 文档检索落地
elasticsearch·搜索引擎·全文检索·nosql·lucene
浅念-3 天前
一文吃透Git:本地操作|冲突处理|远程协作|GitFlow工作流详解
大数据·git·elasticsearch·搜索引擎·gitflow