1、创建索引
##创建一个索引 索引名称为my_index04
##number_of_shards 表示分区个数
##number_of_replicas 副本个数
put /my_index04
{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas" : 1
},
"aliases":{
"aliase111" : {}
},
"mappings" : {
"properties" : {
"id" : {"type":"integer"},
"first_name" : {"type":"text"},
"last_name" : {"type":"text"},
"age" : {"type":"integer"},
"about" : {"type":"text"},
"interests" : {"type":"text"}
}
}
}
创建成功如图:
{
"acknowledged"【响应结果】: true, # true 操作成功
"shards_acknowledged"【分片结果】: true, # 分片操作成功
"index"【索引名称】: "my_index04"
}
注意:创建索引库的分片数默认 1 片,在 7.0.0 之前的 Elasticsearch 版本中,默认 5 片
注意:创建索引的时候名称不能重复,如果出现重复,则会报错,我们可以再次创建名称为my_index04的索引,发现直接报错,如图表示my_index04索引已经存在。
2、查看索引
//查看创建好的索引
get /my_index04
{
"my_index04" : { //索引名称
"aliases" : { //别名
"aliase111" : { }
},
"mappings" : { //文档中字段
"properties" : {
"about" : {
"type" : "text"
},
"age" : {
"type" : "integer"
},
"first_name" : {
"type" : "text"
},
"id" : {
"type" : "integer"
},
"interests" : {
"type" : "text"
},
"last_name" : {
"type" : "text"
}
}
},
"settings" : { //设置
"index" : {
"creation_date" : "1650459667161",
"number_of_shards" : "3", //分片
"number_of_replicas" : "1", //副本
"uuid" : "H3tNKbRhQQ6M47QErbD-Ew",
"version" : {
"created" : "7080099"
},
"provided_name" : "my_index04"
}
}
}
}
索引中各个key的含义:
{
"my_index04"【索引名】: {
"aliases"【别名】: {
},
"mappings"【映射】: {
},
"settings"【设置】: {
"index"【设置 - 索引】: {
"creation_date"【设置 - 索引 - 创建时间】: "1650459667161",
"number_of_shards"【设置 - 索引 - 主分片数量】: "3",
"number_of_replicas"【设置 - 索引 - 副分片数量】: "1",
"uuid"【设置 - 索引 - 唯一标识】: "eI5wemRERTumxGCc1bAk2A",
"version"【设置 - 索引 - 版本】: {
"created": "7080099"
},
"provided_name"【设置 - 索引 - 名称】: "my_index04"
}
}
}
}
3、删除索引
DELETE /my_index04
4、查看所有的索引
get _cat/indices?v
_cat
表示查看的意思,
indices
表示索引
表头
| 含义 |
health | 当前服务器健康状态:green(集群完整) yellow(单点正常、集群不完整) red(单点不正常) |
status | 索引打开、关闭状态 |
index | 索引名 |
uuid | 索引统一编号 |
pri | 主分片数量 |
rep | 副本数量 |
docs.count | 可用文档数量 |
docs.deleted | 文档删除状态(逻辑删除) |
store.size | 主分片和副分片整体占空间大小 |
pri.store.size | 主分片占空间大小 |