需求
我有一个index:test_1,这个index由于各种原因,mapping中出现了下面的type:
"u_ori_id_list" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
我想将u_ori_id_list的类型改为keyword,而且不想丢数据,因此使用Elasticsearch中的reindex来解决。
解决办法
我目前使用的Elasticsearch版本是7.17.7。
首先在目标索引test_2,并将u_ori_id_list字段设置为:
"u_ori_id_list" : {
"type" : "keyword"
}
然后执行下面的语句:
POST _reindex
{
"source": {
"index": "test_1"
},
"dest": {
"index": "test_2"
}
}
由于这一过程可能很长,所以最好不要在kibana中执行,而是使用curl的方式执行。
curl -X POST -H "Content-Type: application/json" http://10.26.120.31:9200/_reindex -d '
{
"source": {
"index": "test_1",
"size": 100
},
"dest": {
"index": "test_2"
}
}'
并且如果不设置"size":100,那么默认的操作是1000,如果数据量太大则会报错:
{"error":{"root_cause":[{"type":"es_rejected_execution_exception","reason":"rejected execution of coordinating operation [coordinating_and_primary_bytes=0, replica_bytes=0, all_bytes=0, coordinating_operation_bytes=859110825, max_coordinating_and_primary_bytes=858993459]"}],"type":"es_rejected_execution_exception","reason":"rejected execution of coordinating operation [coordinating_and_primary_bytes=0, replica_bytes=0, all_bytes=0, coordinating_operation_bytes=859110825, max_coordinating_and_primary_bytes=858993459]"},"status":429}
所以最好设置"size":100
或者可以使用下面的方法:
POST /_reindex?wait_for_completion=false
{
"source": {
"index": "test_1"
},
"dest": {
"index": "test_2"
}
}
通过设置wait_for_completion=false可以获取到一个task_id:
返回task
{
"task" : "_z9sGLZWTZCg_I-OM3H78A:4120835465"
}
使用命令GET _tasks/_z9sGLZWTZCg_I-OM3H78A:4120835465 可以查看当前任务执行进度。
小tips, 可以通过设置excludes来设置要排除的字段:
{
“source”: {
“index”: “源索引名称”,
“_source”: {
“excludes”: [“要排除的字段”]
}
},
“dest”: {
“index”: “目标索引名称”
}
}
1437

被折叠的 条评论
为什么被折叠?



