以下指令,在 kibana dev tools 执行。
创建索引
假设索引名是 movie :
PUT movie
响应:
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "movie"
}
查看索引信息
GET movie
响应:
{
"movie" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1572843447230",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "AzEtRiBaQqO5JDN_l7WG-w",
"version" : {
"created" : "7020099"
},
"provided_name" : "movie"
}
}
}
}
创建索引时指定 mapping 和 settings
PUT movie
{
"mappings" : {
"properties" : {
"name" : {
"type" : "keyword"
}
}
},
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 2
}
}
}
创建文档时自动创建索引
当向一个不存在的索引中写入文档时,会自动创建索引。
POST student/_doc/1
{
"name": "张三"
}
删除索引
DELETE movie
响应:
{
"acknowledged" : true
}
如果在删除之后,再次删除,会因为找不到索引而报错:
{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index [movie]",
"resource.type" : "index_or_alias",
"resource.id" : "movie",
"index_uuid" : "_na_",
"index" : "movie"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index [movie]",
"resource.type" : "index_or_alias",
"resource.id" : "movie",
"index_uuid" : "_na_",
"index" : "movie"
},
"status" : 404
}
删除后再次使用 GET movie
查询索引信息,会报错:
{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index [movie]",
"resource.type" : "index_or_alias",
"resource.id" : "movie",
"index_uuid" : "_na_",
"index" : "movie"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index [movie]",
"resource.type" : "index_or_alias",
"resource.id" : "movie",
"index_uuid" : "_na_",
"index" : "movie"
},
"status" : 404
}