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
}