ElasticSearch 索引和创建、查看、查看所有、删除(kibana操作)

索引

ElasticSearch 中的 索引 相当于 mysql中的 数据库

创建索引

创建索引,就相当于创建 数据库

kibana执行:

  1. PUT /toutiao

返回结果:

  1. {
  2. "acknowledged": true, //true表示创建成功
  3. "shards_acknowledged": true, //分片操作成功
  4. "index": "toutiao" //索引名字
  5. }

创建索引库的分片数默认 1 片,在 7.0 之前默认 5 片

重复创建

重复创建会报错,再次执行,报错如下:

  1. {
  2. "error": {
  3. "root_cause": [
  4. {
  5. "type": "resource_already_exists_exception",
  6. "reason": "index [toutiao/sIiyYbouSsG-5ab0WEqtGg] already exists",
  7. "index_uuid": "sIiyYbouSsG-5ab0WEqtGg",
  8. "index": "toutiao"
  9. }
  10. ],
  11. "type": "resource_already_exists_exception",
  12. "reason": "index [toutiao/sIiyYbouSsG-5ab0WEqtGg] already exists",
  13. "index_uuid": "sIiyYbouSsG-5ab0WEqtGg",
  14. "index": "toutiao"
  15. },
  16. "status": 400
  17. }

提示已经存在

不能使用 POST 请求

不支持 接口幂等性

提示错误如下:

  1. {
  2. "error": "Incorrect HTTP method for uri [/toutiao] and method [POST], allowed: [HEAD, PUT, DELETE, GET]",
  3. "status": 405
  4. }

查看所有索引

kibana执行:

  1. GET _cat/indices?v

解释:

  • _cat:表示查看
  • indices:表示索引
  • v:显示表头

执行结果如下:

  1. health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
  2. green open .kibana-event-log-7.9.3-000001 FRaRCoOTQfWlRU3v3Xxr6Q 1 0 1 0 5.5kb 5.5kb
  3. green open .apm-custom-link NUfs6ErcQQa0_yViRuvKvg 1 0 0 0 208b 208b
  4. green open .kibana_task_manager_1 kovAZ2HXSiS6T5HYLk7SCg 1 0 6 4059 770kb 770kb
  5. green open .apm-agent-configuration YA6JNB8ET5OKdmbiyLcSWg 1 0 0 0 208b 208b
  6. green open .kibana_1 3VRWlatiS-mOB5n3oenANg 1 0 14 6 10.4mb 10.4mb
  7. yellow open toutiao sIiyYbouSsG-5ab0WEqtGg 1 1 0 0 208b 208b
  8. 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执行:

  1. GET /toutiao

执行结果如下:

  1. {
  2. "toutiao": { //索引名
  3. "aliases": {}, //别名
  4. "mappings": {}, //映射
  5. "settings": { //设置
  6. "index": { //索引
  7. "creation_date": "1630241938826", //创建时间
  8. "number_of_shards": "1", //主分片数量
  9. "number_of_replicas": "1", //副分片数量
  10. "uuid": "sIiyYbouSsG-5ab0WEqtGg", //唯一标识
  11. "version": { //版本
  12. "created": "7090399"
  13. },
  14. "provided_name": "toutiao" //索引名称
  15. }
  16. }
  17. }
  18. }

删除索引

kibana执行:

  1. DELETE /toutiao

执行结果如下:

  1. {
  2. "acknowledged": true
  3. }

原文出处:http://malaoshi.top/show_1IX2PVMXbETt.html