索引
ElasticSearch 中的 索引 相当于 mysql中的 数据库
创建索引
创建索引,就相当于创建 数据库
kibana执行:
PUT /toutiao
返回结果:
{
"acknowledged": true, //true表示创建成功
"shards_acknowledged": true, //分片操作成功
"index": "toutiao" //索引名字
}
创建索引库的分片数默认 1 片,在 7.0 之前默认 5 片
重复创建
重复创建会报错,再次执行,报错如下:
{
"error": {
"root_cause": [
{
"type": "resource_already_exists_exception",
"reason": "index [toutiao/sIiyYbouSsG-5ab0WEqtGg] already exists",
"index_uuid": "sIiyYbouSsG-5ab0WEqtGg",
"index": "toutiao"
}
],
"type": "resource_already_exists_exception",
"reason": "index [toutiao/sIiyYbouSsG-5ab0WEqtGg] already exists",
"index_uuid": "sIiyYbouSsG-5ab0WEqtGg",
"index": "toutiao"
},
"status": 400
}
提示已经存在
不能使用 POST 请求
不支持 接口幂等性
提示错误如下:
{
"error": "Incorrect HTTP method for uri [/toutiao] and method [POST], allowed: [HEAD, PUT, DELETE, GET]",
"status": 405
}
查看所有索引
kibana执行:
GET _cat/indices?v
解释:
_cat
:表示查看indices
:表示索引v
:显示表头
执行结果如下:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .kibana-event-log-7.9.3-000001 FRaRCoOTQfWlRU3v3Xxr6Q 1 0 1 0 5.5kb 5.5kb
green open .apm-custom-link NUfs6ErcQQa0_yViRuvKvg 1 0 0 0 208b 208b
green open .kibana_task_manager_1 kovAZ2HXSiS6T5HYLk7SCg 1 0 6 4059 770kb 770kb
green open .apm-agent-configuration YA6JNB8ET5OKdmbiyLcSWg 1 0 0 0 208b 208b
green open .kibana_1 3VRWlatiS-mOB5n3oenANg 1 0 14 6 10.4mb 10.4mb
yellow open toutiao sIiyYbouSsG-5ab0WEqtGg 1 1 0 0 208b 208b
yellow open customer JsAZPZRgSLadpKFbU_AfhA 1 1 1 0 3.8kb 3.8kb
解释:
- health 当前服务器健康状态:
- green:集群完整
- yellow:单点正常、集群不完整
- red:单点不正常
- status 索引打开、关闭状态
- index 索引名
- uuid 索引统一编号
- pri 主分片数量
- rep 副本数量
- docs.count 可用文档数量
- docs.deleted 文档删除状态(逻辑删除)
- store.size 主分片和副分片整体占空间大小
- pri.store.size 主分片占空间大小
查看指定索引
kibana执行:
GET /toutiao
执行结果如下:
{
"toutiao": { //索引名
"aliases": {}, //别名
"mappings": {}, //映射
"settings": { //设置
"index": { //索引
"creation_date": "1630241938826", //创建时间
"number_of_shards": "1", //主分片数量
"number_of_replicas": "1", //副分片数量
"uuid": "sIiyYbouSsG-5ab0WEqtGg", //唯一标识
"version": { //版本
"created": "7090399"
},
"provided_name": "toutiao" //索引名称
}
}
}
}
删除索引
kibana执行:
DELETE /toutiao
执行结果如下:
{
"acknowledged": true
}