索引管理
- 索引管理的引入
- 索引的格式
- 索引管理操作
- 创建索引
- 修改索引
- 打开/关闭索引
- 删除索引
- 查看索引
索引管理的引入
PUT /customer/_doc/1
{
"name": "John Doe"
}
而这个index实际上已经自动创建了它里面的字段(name)的类型。我们不妨看下它自动创建的mapping:
{
"mappings": {
"_doc": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
第一个禁止自动创建索引,第二个是手动创建索引。
- 禁止自动创建索引
vi config/elasticsearch.yml
action.auto_create_index: false
索引的格式
在请求体里面传入设置或类型映射,如下所示:
PUT /my_index
{
"settings": { ... any settings ... },
"mappings": {
"properties": { ... any properties ... }
}
}
- settings: 用来设置分片,副本等配置信息
- mappings: 字段映射,类型等
索引管理操作
创建索引
PUT /test-index-users
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"age": {
"type": "long"
},
"remarks": {
"type": "text"
}
}
}
}
修改索引
修改副本为0
PUT /test-index-users/_settings
{
"settings": {
"number_of_replicas": 0
}
}
打开/关闭索引
- 关闭索引
一旦索引被关闭,那么这个索引只能显示元数据信息,不能够进行读写操作。
POST /test-index/_close
- 开启索引
POST /test-index/_open
删除索引
DELETE /test-index
查看索引
- 查看mapping
GET /index/_mapping
- 查看setting
GET /index/_setting
- 查看所有
GET /index