簡體   English   中英

elasticsearch新建索引時默認設置3個分片

[英]set 3 shards by default when creating a new index in elasticsearch

每當創建新索引時,我想默認使用 3 個分片和 1 個副本創建它,但未在 curl 中提供詳細信息,如下所示。

curl -X PUT "localhost:9200/my-index-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index": {
      "number_of_shards": 3,  
      "number_of_replicas": 1
    }
  }
}
'

我可以在 elasticsearch.yml 中設置什么屬性,以便任何新索引創建都需要 3 個物理分片和 1 個副本?

所以,

curl -X PUT "localhost:9200/my-index-000001?pretty"

應該創建具有 3 個分片和 1 個副本的索引。 我知道默認情況下它會創建 1 個分片和 1 個副本。

文檔: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html

最簡單的方法是創建一個匹配所有索引的索引模板,如下所示:

PUT _index_template/all_indexes
{
  "index_patterns": ["*"],
  "template": {
    "settings": {
      "number_of_shards": 3,
      "number_of_replicas": 1
    },
    "mappings": {},
    "aliases": {}
  },
  "priority": 1,
  "composed_of": []
}

由於所有索引都將匹配* ,因此它們都將使用所需的設置創建,如果需要,您還可以使用更具體的索引模板覆蓋這些設置。

我又找到了一種方法。 這僅適用於 5.X 之前的版本我們可以在 elasticsearch.yml 文件中添加屬性

index.number_of_shards: 3
index.number_of_replicas: 1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM