在create index docs之后,我知道如何使用自定义设置创建索引,即
PUT /my-new-index
{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}
}
是否可以使用相同的设置一次初始化多个索引?我在看类似delete index API的东西,它允许查询形式
DELETE /index1,index2,index3
一次删除多个索引。
最佳答案
您可以使用index template
API在其他索引中使用相同的设置。Create index
API不支持多个索引创建。
Put index template API
Index templates define settings and mappings that you can automatically apply when creating new indices. Elasticsearch applies templates to new indices based on an index pattern that matches the index name.
PUT _template/template_1
{
"index_patterns": ["*"],
"settings": {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}
然后创建一个索引
PUT my_index
{
"mappings": {
"properties": {
"content": {
"type": "text"
}
}
}
}
获取索引设置
GET my_index/_settings
{
"my_index" : {
"settings" : {
"index" : {
"creation_date" : "1575300164818",
"number_of_shards" : "3",
"number_of_replicas" : "2",
"uuid" : "SfRWgW96RX2a0rRYNtdodA",
"version" : {
"created" : "7040199"
},
"provided_name" : "my_index"
}
}
}
}
在结果中查看
number_of_shards
和number_of_replicas
。希望这可以帮助
关于elasticsearch - 有没有一种方法可以通过单个查询创建多个ElasticSearch索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59141297/