ES之索引操作(入门)

ES之索引操作(入门)

一、创建索引
1.向ES服务器发出 【PUT】 请求:http://127.0.0.1:9200/test-index-1,会创建一个名为test-index-1的索引,返回结果如下。

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "test"
}

2.如果再次创建相同的索引,.向ES服务器发出 【PUT】 请求:http://127.0.0.1:9200/test-index-1,会提示索引已经存在。

{
    "error": {
        "root_cause": [
            {
                "type": "resource_already_exists_exception",
                "reason": "index [test-index-1/YTJUhyJNQUa-GlH3F1Stvg] already exists",
                "index_uuid": "YTJUhyJNQUa-GlH3F1Stvg",
                "index": "test-index-1"
            }
        ],
        "type": "resource_already_exists_exception",
        "reason": "index [test-index-1/YTJUhyJNQUa-GlH3F1Stvg] already exists",
        "index_uuid": "YTJUhyJNQUa-GlH3F1Stvg",
        "index": "test-index-1"
    },
    "status": 400
}

二、索引查询
1.查询索引名为test-index-1的相关信息
【GET】 请求:http://127.0.0.1:9200/test-index-1

{
    "test-index-1": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "routing": {
                    "allocation": {
                        "include": {
                            "_tier_preference": "data_content"
                        }
                    }
                },
                "number_of_shards": "1",
                "provided_name": "test-index-1",
                "creation_date": "1635770982635",
                "number_of_replicas": "1",
                "uuid": "YTJUhyJNQUa-GlH3F1Stvg",
                "version": {
                    "created": "7140299"
                }
            }
        }
    }
}

2.查询ES中所有索引的信息
【GET】请求:http://127.0.0.1:9200/_cat/indices?v

参数"v"表示展示详细信息

health status index            uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   .geoip_databases j4oGXmv7SkefSwnzSoIgZQ   1   0         41            0     40.3mb         40.3mb
yellow open   test             hCtSSMGnSDWZ41yXS81hGg   1   1          0            0       208b           208b
yellow open   test-index-1     YTJUhyJNQUa-GlH3F1Stvg   1   1          0            0       208b           208b
yellow open   test-index-2     ZX2u0tZUSs-2pzRGTjAbdw   1   1          0            0       208b           208b
yellow open   test-index-3     G7-Eu3AdQ3eCjfRm9RHqMg   1   1          0            0       208b           208b

三、删除索引
1.删除索引名为test-index-3的索引
【DELETE】请求:http://127.0.0.1:9200/test-index-3

{
    "acknowledged": true
}

2.再次执行会提示没有此索引

{
    "error": {
        "root_cause": [
            {
                "type": "index_not_found_exception",
                "reason": "no such index [test-index-3]",
                "resource.type": "index_or_alias",
                "resource.id": "test-index-3",
                "index_uuid": "_na_",
                "index": "test-index-3"
            }
        ],
        "type": "index_not_found_exception",
        "reason": "no such index [test-index-3]",
        "resource.type": "index_or_alias",
        "resource.id": "test-index-3",
        "index_uuid": "_na_",
        "index": "test-index-3"
    },
    "status": 404
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值