Elasticsearch7.9:一、索引基础
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