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
}
网友评论