index
通过创建template
来进行动态模版的创建。
- 创建模版
PUT _template/template_1
{
"template": "test-*",
"settings": {
"number_of_shards": 1
},
"mappings": {
"type1": {
"_source": {
"enabled": false
},
"properties": {
"host_name": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z YYYY"
}
}
}
}
}
- 创建第一天的数据
PUT test-2018.08.10/type1
{
"host_name":"",
"created_at":""
}
- 创建第二天的数据
PUT test-2018.08.11/type1
{
"host_name":"",
"created_at":""
}
后面都是依次类推。
禁止自动创建索引
vim config/elasticsearch.yml
action.auto_create_index: false
删除索引
#用以下的请求来 删除索引:
DELETE /my_index
#你也可以这样删除多个索引:
DELETE /index_one,index_two
DELETE /index_*
#你甚至可以这样删除 全部 索引:
DELETE /_all
DELETE /*
为了避免意外的执行了删除所有数据的命令,可加入如下的配置。
vim config/elasticsearch.yml
action.destructive_requires_name: true
# 配置之后就不能再执行删除所有的数据的命令,只能指定索引的删除
索引设置
可以通过修改配置自定义索引行为,详细配置参照索引模块。