创建新索引
PUT /my_index
{
"settings": {
"number_of_shards": "50", // 分片大小
"number_of_replicas": "0", // 副本为0
"index": {
"refresh_interval": "-1" // 禁止自动刷新数据
}
},
"mappings": {
"XXX":{
"properties": {
"id":{"type": "keyword"},
"name":{
"type": "text",
"analyzer": "standard"
},
"about":{
"type": "text",
"analyzer": "whitespace"
},
"geo":{
"type": "geo_point"
}
}
}
}
}
PUT /_cluster/settings
{
"transient" : {
"indices.store.throttle.type" : "none"
}
}
全量复制索引
//wait_for_completion=false参数,reindex将直接返回taskId。
POST _reindex?wait_for_completion=false
{
"source": {
"index": "old_index", //原有索引
"size": 5000 //一个批次处理的数据量
},
"dest": {
"index": "new_index", //目标索引
}
}
GET /_tasks/taskId:1
POST _tasks/task_id:1/_cancel
增量复制索引
POST /_reindex
{
"conflicts": "proceed", //意思是冲突以旧索引为准,直接跳过冲突,否则会抛出异常,停止task
"source": {
"index": "old_index" //旧索引
"query": {
"constant_score" : {
"filter" : {
"range" : {
"data_update_time" : {
"gte" : 123456789 //reindex开始时刻前的毫秒时间戳
}
}
}
}
}
},
"dest": {
"index": "new_index", //新索引
"version_type": "external" //以旧索引的数据为准
}
}
切换索引
PUT XXX/_settings
{
"index": {
"refresh_interval": "3" // 禁止自动刷新数据
}
}
PUT /_cluster/settings
{
"transient" : {
"indices.store.throttle.type" : "merge"
}
}