1、索引命名規范
索引命名有如下限制:
- 僅限小寫字母
- 不能包含
\
、/
、*
、?
、"
、<
、>
、|
、# 以及 空格符等 特殊符號 - 從 7.0 版本開始不再包含 冒號
- 不能以
-
、_
或+
開頭 - 不能超過 255 個字節(注意它是字節,因此多字節字符將計入255個限制)
2、新建索引
(1)索引名小寫
(2)索引名不能包含大些字母
PUT Blog
{
"error": {
"root_cause": [
{
"type": "invalid_index_name_exception",
"reason": "Invalid index name [Blog], must be lowercase",
"index_uuid": "_na_",
"index": "Blog"
}
],
"type": "invalid_index_name_exception",
"reason": "Invalid index name [Blog], must be lowercase",
"index_uuid": "_na_",
"index": "Blog"
},
"status": 400
}
3、索引配置
創建索引時,可以制定相關設置,比如設置索引的分片數 number_of_shards 和 副本數 number_of_replicas
PUT blog
{
"settings" : {
"index" : {
"number_of_shards" : 2,
"number_of_replicas" : 2
}
}
}
也可以簡化為:
PUT blog
{
"settings" : {
"number_of_shards" : 2,
"number_of_replicas" : 2
}
}
也就是說,不必在settings部分中明確指定索引部分。
4、查看索引及配置信息
(1)查看制定索引
GET blog
(2)查看索引列表
GET /_cat/indices?v
(3)判定索引是否存在
HEAD blog
5、索引別名
(1)添加別名
POST _aliases
{
"actions": [
{
"add": {
"indices": ["index2","test"],
"alias": "alias1"
}
}
]
}
(2)移除別名
POST _aliases
{
"actions": [
{
"remove": {
"index": "test",
"alias": "alias1"
}
}
]
}
(3)查看別名
GET alias1