1、为什么我们要手动创建索引?
某些字段如姓名,邮箱等不需要分词,不能直接自动创建
2、创建索引
创建索引的语法
PUT /my_index
{
“settings”: { … any settings … },
“mappings”: {
“type_one”: { … any mappings … },
“type_two”: { … any mappings … },
…
}
}
创建索引的示例
PUT /my_index
{
“settings”: {
“number_of_shards”: 1,
“number_of_replicas”: 0
},
“mappings”: {
“my_type”: {
“properties”: {
“my_field”: {
“type”: “text”
}
}
}
}
}
3、修改索引
PUT /my_index/_settings
{
“number_of_replicas”: 1
}
4、删除索引
删一个索引: DELETE /my_index
删多个索引: DELETE /index_one,index_two
通配符删索引: DELETE /index_*
删除所有索引: DELETE /_all
在elasticsearch.yml 设置
action.destructive_requires_name: true
这样就不会使用delete /_all 删除所有的索引。只能一个一个的删除。