Es6.X版本ReIndex问题
2020-02-11 本文已影响0人
梦想又照进现实
背景
当我们需要做数据拷贝时候使用了Reindex后,再对该index进行数据插入时候,如果按默认的index和type一致的方式来,会报如下错误:
Rejecting mapping update to [lu53pqs201901] as the final mapping would have
more than 1 type: [lu53pqs201901, lu53pqs201905]"
原因
查看我们现在的index的mapping信息发现其type信息定义如下:
"lu53pqs201901": {
"mappings": {
"lu53pqs201905": {
"properties": {
"busiTyp": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
...
type的名字沿用了原来被拷贝index的名字,而我们目前使用的es版本为es-version-6.1.4,不允许出现多type,从而报错;
解决办法
ReIndex方法在默认情况下是这样的:
{
"source": {
"index": "lu53pqs201905"
},
"dest": {
"index": "lu53pqs201901"
}
}
这样就会导致重建完的type是源index这边的默认的,从而导致于目标不一致,在Reindex的参数还有很多用于控制重建,比较完整的版本是:
POST _reindex
{
"source": {
"index": "index_name_1",
"type": [
"type_name_1",
"type_name_2"
],
"query": {//query的条件
"term": {
"user": "kimchy"
}
}
},
"dest": {
"index": "index_name_2",
"type": [
"type_name_3",
"type_name_4"
]
}
}
官方API:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html
官方API并没有提目标index下的type设置问题,不知道是为什么?
针对上面的我们的拷贝比较合理的写法就是:
POST _reindex
{
"source": {
"index": "lu53pqs201905",
"type": "lu53pqs201905"
},
"dest": {
"index": "lu53pqs201901",
"type": "lu53pqs201901"
}
}