ES 调整分片和副本数

一、调整副本数

如调整副本数为0

1
2
3
4
5
6
curl -XPUT 'node3:9205/downloads/_settings' -d '{
"index": {
"number_of_replicas": "0"
}
}'

返回

1
{"acknowledged":true}

二、调整索引分片

索引分片数在索引创建好了之后就不能调整了,只能重建索引

(ES 5.X 版本中有一个缩小分片的api,需要先设置为只读,然后缩减过程需要大量的IO)

先创建索引

1
2
3
4
5
6
7
8
curl -XPUT 'http://localhost:9200/wwh_test2/' -d '{
"settings" : {
"index" : {
"number_of_shards" : 2,
"number_of_replicas" : 2
}
}
}'

或者同时指定mappings

1
2
3
4
5
6
7
8
9
10
11
12
curl -XPOST localhost:9200/test -d '{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"type1" : {
"properties" : {
"field1" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}'

之后再进行重新索引

1
2
3
4
5
6
7
8
curl -XPOST 'http://localhost:9200/_reindex' -d '{
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter"
}
}'

开关索引

关闭

1
2
curl -XPOST 'localhost:9200/lookupindex/_close'

打开

1
2
curl -XPOST 'localhost:9200/lookupindex/_open'