elasticsearch - 有没有一种方法可以通过单个查询创建多个ElasticSearch索引

标签 elasticsearch

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_shardsnumber_of_replicas

希望这可以帮助

关于elasticsearch - 有没有一种方法可以通过单个查询创建多个ElasticSearch索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59141297/

相关文章:

autocomplete - 在elasticsearch中突出显示部分单词

elasticsearch - 查找某个父级的嵌套结果

elasticsearch - Kibana日期过滤器对于丰富处理器创建的索引无效

java - Elasticsearch 通过过滤器获取所有数据

ruby-on-rails - 事件记录模型中具有替代搜索的轮胎elasticsearch kaminari分页

azure - Elasticsearch 快照到 Azure Blob 存储 - 找不到帐户的 azure 客户端

python - 模拟 elasticsearch-py 调用

elasticsearch - 您如何在 ElasticSearch 内联脚本中使用 min/max?

ruby-on-rails - 使用轮胎 gem 为特定领域设置 Elasticsearch 分析器

elasticsearch - 复制 Elasticsearch 主分片