更新新索引的默认索引number_of_replicas设置 [英] Updating the default index number_of_replicas setting for new indices
问题描述
根据文档
curl -XPUT 'localhost:9200/_settings' -d '
{ "index" : { "number_of_replicas" : 4 } }'
正确更改现有节点的副本数。但是,当logstash在第二天创建一个新的索引时,将number_of_replicas设置为旧值。
This correctly changes the replica count for existing nodes. However, when logstash creates a new index the following day, number_of_replicas is set to the old value.
有没有办法永久更改此设置的默认值,无需更新集群中的所有 elasticsearch.yml
文件并重新启动服务?
Is there a way to permanently change the default value for this setting without updating all the elasticsearch.yml
files in the cluster and restarting the services?
FWIW我也尝试过
FWIW I've also tried
curl -XPUT 'localhost:9200/logstash-*/_settings' -d '
{ "index" : { "number_of_replicas" : 4 } }'
无效。
推荐答案
可以使用索引模板。索引模板是为集群中创建的新索引设置默认设置(包括映射)的好方法。
Yes, you can use index templates. Index templates are a great way to set default settings (including mappings) for new indices created in a cluster.
索引模板
索引模板允许定义将自动为
应用于创建的新索引的模板。模板包括设置
和映射,以及一个简单的模式模板,用于控制是否将
模板应用于创建的索引。
Index templates allow to define templates that will automatically be applied to new indices created. The templates include both settings and mappings, and a simple pattern template that controls if the template will be applied to the index created.
http://www.elasticsearch.org/guide /en/elasticsearch/reference/current/indices-templates.html
例如:
curl -XPUT 'localhost:9200/_template/logstash_template' -d '
{
"template" : "logstash-*",
"settings" : {"number_of_replicas" : 4 }
} '
这将设置默认与名称logstash- *匹配的所有新索引的副本数为4。请注意,这不会更改现有索引,只会更改新创建的索引。
This will set the default number of replicas to 4 for all new indexes that match the name "logstash-*". Note that this will not change existing indexes, only newly created ones.
这篇关于更新新索引的默认索引number_of_replicas设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!