[英]Modify default number of Elasticsearch shards
如果我有一個15節點集群,我是否必須更改
index.number_of_shards
在新值對新索引生效之前,所有15個節點上的值並重新啟動它們?
在ElasticSearch中設置索引的分片數后,就無法更改它們。 您需要使用所需數量的分片創建一個新索引,並根據您的使用情況,您可能希望將數據傳輸到新索引。
我說根據用例,因為,例如,如果你存儲基於時間的數據,如日志事件,關閉一個索引並打開一個具有不同數量的分片的新索引,並將所有數據轉發為索引是完全合理的到那個新索引,保留舊索引進行搜索。
但是,如果您的用例是,例如,存儲博客文檔,並且您的索引是按主題划分的,那么您將需要(a)使用不同數量的分片創建如上所述的新索引,以及(b)重新索引您的數據。 對於(b)我建議使用Scroll and Scan API從舊索引中獲取數據。
請記住,指定分片數是靜態操作,應在創建索引時完成。 但是,創建索引后的任何更改都需要重新完成重新索引,這需要時間。
要在創建索引時創建分片數,請使用此命令。
curl -XPUT 'localhost:9200/my_sample_index?pretty' -H 'Content-Type: application/json' -d' { “settings:”{ “number_of_shards”:2, “number_of_replicas”:0 } }
您不必在所有節點上運行它。 在任何一個節點上運行它們。 所有節點都相互通信關於彈性指數的變化。
您需要為將要創建的新索引創建模板:
PUT /_template/index_defaults
{
"index_patterns": "*",
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 1
}
}
}
對於舊索引,您需要重新索引。
示例:從my_old_index到my_new_index
使用適當的映射和設置創建新索引:
PUT my_new_index
{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 1
}
}
}
從舊索引重新索引到新索引,僅在您需要時指定類型:
POST /_reindex?slices=5
{
"size": 100000,
"source": { "index": "my_old_index" },
"dest": { "index": "my_new_index", "type": "my_type" }
}
更新了語法以避免Elasticsearch 6+中的某些棄用警告
根據https://www.elastic.co/guide/en/elasticsearch/reference/6.0/indices-templates.html
PUT /_template/index_defaults
{
"index_patterns": ["*"],
"order" : 0,
"settings": {
"number_of_shards": 2
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.