美文网首页
012.Elasticsearch索引管理入门篇

012.Elasticsearch索引管理入门篇

作者: CoderJed | 来源:发表于2020-06-18 15:09 被阅读0次

1.1 创建索引

[root@node01 ~]# curl -X PUT "node01:9200/index1"

# 返回
{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "index1"
}

1.2 查看索引

[root@node01 ~]# curl -X GET "node01:9200/index1"

# 返回
{
    "index1": {
        "aliases": {},
        "mappings": {}, # 字段信息
        "settings": {
            "index": {
                "creation_date": "1586503723100",
                "number_of_shards": "5", # 默认shard数:5
                "number_of_replicas": "1", # 默认replica数:1
                "uuid": "mnGGs-8yTbuDrcbwUmdTZQ",
                "version": {
                    "created": "6060099"
                },
                "provided_name": "index1"
            }
        }
    }
}

1.3 删除索引

curl -X DELETE "node01:9200/index1"

# 返回
{
    "acknowledged": true
}

# 语法 
DELETE /index_name1
DELETE /index_name1,index_name2
DELETE /index_prefix*
DELETE /_all

补充:
不允许删除全部索引(DELETE /_all)的配置:

action.destructive_requires_name: true

1.4 批量查看索引

curl -X GET "node01:9200/index1,index2"

# 返回
{
    "index1": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1586504252493",
                "number_of_shards": "5",
                "number_of_replicas": "1",
                "uuid": "ICoU-6pfT36cHvEGSys7Ww",
                "version": {
                    "created": "6060099"
                },
                "provided_name": "index1"
            }
        }
    },
    "index2": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1586504255661",
                "number_of_shards": "5",
                "number_of_replicas": "1",
                "uuid": "r3bVxPGRQUC1aZslG2N3yw",
                "version": {
                    "created": "6060099"
                },
                "provided_name": "index2"
            }
        }
    }
}

1.5 查看全部索引

# 方法一
curl -X GET "node01:9200/_all"
# 返回
{
    "index1": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1586504252493",
                "number_of_shards": "5",
                "number_of_replicas": "1",
                "uuid": "ICoU-6pfT36cHvEGSys7Ww",
                "version": {
                    "created": "6060099"
                },
                "provided_name": "index1"
            }
        }
    },
    "index2": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1586504255661",
                "number_of_shards": "5",
                "number_of_replicas": "1",
                "uuid": "r3bVxPGRQUC1aZslG2N3yw",
                "version": {
                    "created": "6060099"
                },
                "provided_name": "index2"
            }
        }
    },
    "index3": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1586504463960",
                "number_of_shards": "5",
                "number_of_replicas": "1",
                "uuid": "CrtgrJ7QSdyz0Qow_i0pBg",
                "version": {
                    "created": "6060099"
                },
                "provided_name": "index3"
            }
        }
    },
    "test_index": {
        "aliases": {},
        "mappings": {
            "test_type": {
                "properties": {
                    "message": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "user": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    }
                }
            }
        },
        "settings": {
            "index": {
                "creation_date": "1586503491778",
                "number_of_shards": "5",
                "number_of_replicas": "1",
                "uuid": "KyWsIMTDQUyNPmRsR0DEvw",
                "version": {
                    "created": "6060099"
                },
                "provided_name": "test_index"
            }
        }
    }
}

# 方法二
curl -X GET "node01:9200/_cat/indices?v"
# 返回
health status index      uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   index2     r3bVxPGRQUC1aZslG2N3yw   5   1          0            0      1.2kb          1.2kb
yellow open   index1     ICoU-6pfT36cHvEGSys7Ww   5   1          0            0      1.2kb          1.2kb
yellow open   test_index KyWsIMTDQUyNPmRsR0DEvw   5   1          1            0        5kb            5kb
yellow open   index3     CrtgrJ7QSdyz0Qow_i0pBg   5   1          0            0      1.1kb          1.1kb

1.6 判断索引是否存在

[root@node01 ~]# curl -I "node01:9200/index1"
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 231

[root@node01 ~]# curl -I "node01:9200/index100"
HTTP/1.1 404 Not Found
content-type: application/json; charset=UTF-8
content-length: 355

1.7 关闭索引

[root@node01 ~]# curl -X POST "node01:9200/index1/_close"
{
    "acknowledged":true
}

1.8 开启索引

[root@node01 ~]# curl -X POST "node01:9200/index1/_open"
{
    "acknowledged":true,
    "shards_acknowledged":true
}

相关文章

  • 012.Elasticsearch索引管理入门篇

    1.1 创建索引 1.2 查看索引 1.3 删除索引 补充:不允许删除全部索引(DELETE /_all)的配置:...

  • 系统学习绩效管理第二天(D17)

    《绩效管理从入门到精通》分三块内容:入门篇、提升篇、精通篇。看了目录,入门篇内包含两部分:1.根据绩效管理流程分别...

  • es索引管理

    索引管理[https://www.elastic.co/subscriptions] 索引管理使您能够查看索引设置...

  • MongoDB学习报告(二)

    概述 MongoDB索引管理MongoDB查询优化 MongoDB索引管理 单键索引中的每一项都应该对应被索引文档...

  • 卓_睿文章合集

    一周总结 致已逝的第10周致已逝的第9周 月总结 2017年4月总结 学习方法 入门篇 时间管理 入门篇 游·记 ...

  • mysql索引

    管理索引相关语句 查看索引:show index from [table_name];创建索引:alter tab...

  • 索引管理

    索引是具有相同结构的文档集合.例如,可以有一个客户的索引,包括一个产品目录的索引,一个订单数据的索引等.创建索引时...

  • 索引管理

    https://www.elastic.co/guide/cn/elasticsearch/guide/curre...

  • day06

    6.7 索引的操作管理 1.添加索引 2.查看索引 3.创建唯一索引 4.创建前缀索引 5.创建联合索引 6.删除...

  • mysql 索引管理

    [TOC] 索引管理 按特定数据结构存储的数据 索引类型 聚集索引、非聚集索引: 数据是否与索引存储在一起 主键索...

网友评论

      本文标题:012.Elasticsearch索引管理入门篇

      本文链接:https://www.haomeiwen.com/subject/odeuxktx.html