Elasticsearch 7.x:2、索引管理
https://www.elastic.co/guide/en/elasticsearch/reference/7.x/index.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
2.1 索引名規範
索引命名有如下限制:
- 僅限小寫字母
- 不能包含
\
、/
、*
、?
、"
、<
、>
、|
、#以及空格符等特殊符號 - 從7.0版本開始不再包含冒號
- 不能以
-
、_
或+
開頭 - 不能超過255個位元組(注意它是位元組,因此多位元組字元將計入255個限制)
2.2 新建索引
(1)索引名小寫
PUT test
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "test"
}
(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)重複建立索引
PUT test
相應結果:
{
"error": {
"root_cause": [
{
"type": "resource_already_exists_exception",
"reason": "index [test/XBKm9hVxSQGP6KTncA10WA] already exists",
"index_uuid": "XBKm9hVxSQGP6KTncA10WA",
"index": "test"
}
],
"type": "resource_already_exists_exception",
"reason": "index [test/XBKm9hVxSQGP6KTncA10WA] already exists",
"index_uuid": "XBKm9hVxSQGP6KTncA10WA",
"index": "test"
},
"status": 400
}
2.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部分中明確指定索引部分。
相應結果:
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "blog"
}
2.4 檢視索引
(1)檢視制定索引
GET blog
相應結果:
{
"blog" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1547012455291",
"number_of_shards" : "2",
"number_of_replicas" : "2",
"uuid" : "RorVlzACQIOpGDCW9LJ1cA",
"version" : {
"created" : "6050499"
},
"provided_name" : "blog"
}
}
}
}
(2)檢視索引列表
GET /_cat/indices?v
相應結果如下,可以看到兩個剛剛建立的索引,.kibana_1
是Kibana自帶樣例索引。
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open blog RorVlzACQIOpGDCW9LJ1cA 2 2 0 0 522b 522b
green open .kibana_1 vfaeT7wQSgyxXOlZioCFDQ 1 0 3 0 11.9kb 11.9kb
yellow open test k4WAeNOqSpGzQbO3euWy2w 1 1 0 0 230b 230b
需要注意:我們新建的索引,預設分片和副本都是1。
(3)判定索引是否存在
HEAD blog
相應結果:
200 - OK
2.5 更新副本數
PUT blog/_settings
{
"number_of_replicas": 1
}
相應結果:
{
"acknowledged" : true
}
2.6 檢視索引配置資訊
GET blog/_settings
相應結果:
{
"blog" : {
"settings" : {
"index" : {
"creation_date" : "1547012455291",
"number_of_shards" : "2",
"number_of_replicas" : "1",
"uuid" : "RorVlzACQIOpGDCW9LJ1cA",
"version" : {
"created" : "6050499"
},
"provided_name" : "blog"
}
}
}
}
2.7 刪除索引
可以直接使用DELETE命令刪除索引
DELETE test
相應結果:
{
"acknowledged" : true
}
2.8 索引的關閉與開啟
一個關閉的索引幾乎不佔用系統資源。我們可以臨時關閉某個索引,在需要時再重新開啟該索引。
(1)關閉blog
POST blog/_close
相應結果:
{
"acknowledged" : true
}
(2)檢視索引
GET /_cat/indices?v
相應結果:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
close blog RorVlzACQIOpGDCW9LJ1cA
green open .kibana_1 vfaeT7wQSgyxXOlZioCFDQ 1 0 3 0 11.9kb 11.9kb
(3)重新開啟blog
POST blog/_open
相應結果:
{
"acknowledged" : true,
"shards_acknowledged" : true
}
2.9 指定type的mapping
創新索引時,允許提供一個type的對映。
創新建立索引test,並制定預設_doc型別的mappings
PUT test
{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"_doc" : {
"properties" : {
"field1" : { "type" : "text" }
}
}
}
}
相應結果:
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "test"
}
2.10 索引別名
索引別名不僅僅可以關聯一個索引,它能聚合多個索引。此外,一個別名也可以與一個過濾器相關聯, 這個過濾器在搜尋和路由的時候被自動應用。
(1)建立多個索引
PUT index1
PUT index2
(2)建立index1的別名alias1
POST _aliases
{
"actions": [
{
"add": {
"index": "index1",
"alias": "alias1"
}
}
]
}
{
"acknowledged" : true
}
說明:此時別名alias1和index1一對一。
(3)新增多個索引的別名
POST _aliases
{
"actions": [
{
"add": {
"indices": ["index2","test"],
"alias": "alias1"
}
}
]
}
{
"acknowledged" : true
}
說明:我們是不能對alias1進行寫操作,當有多個索引時的別名,不能區分到底操作哪一個索引。
(4)移除別名
POST _aliases
{
"actions": [
{
"remove": {
"index": "test",
"alias": "alias1"
}
}
]
}
{
"acknowledged" : true
}
(5)檢視別名
GET alias1
{
"index1" : {
"aliases" : {
"alias1" : { }
},
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1547013859010",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "sbbArnOvTYqf07rXlTpFtA",
"version" : {
"created" : "6050499"
},
"provided_name" : "index1"
}
}
},
"index2" : {
"aliases" : {
"alias1" : { }
},
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1547013863297",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "qqRkUXOcQfuBTf1eBqvMPA",
"version" : {
"created" : "6050499"
},
"provided_name" : "index2"
}
}
}
}
相關文章
- Elasticsearch 7.x 之文件、索引和 REST API 【基礎入門篇】Elasticsearch索引RESTAPI
- ES ElasticSearch 7.x 下動態擴大索引的shard數量Elasticsearch索引
- Elasticsearch 索引容量管理實踐Elasticsearch索引
- Elasticsearch索引生命週期管理方案Elasticsearch索引
- Elasticsearch ILM DSL 索引生命週期管理Elasticsearch索引
- 【ElasticSearch】ElasticSearch 7.x 預設不在支援指定索引型別 Failed to parse mapping [_doc]: Root mapping definitioElasticsearch索引型別AIAPP
- 【Elasticsearch】Elasticsearch 索引模板Elasticsearch索引
- elasticsearch 6.x 與elasticsearch 7.x 配置與使用(Java)ElasticsearchJava
- Elasticsearch索引。Elasticsearch索引
- Elasticsearch系列---生產叢集的索引管理Elasticsearch索引
- Elasticsearch 7.x 安裝及配置指導Elasticsearch
- ElasticSearch 索引 VS MySQL 索引Elasticsearch索引MySql
- ElasticSearch生命週期管理-索引策略配置與操作Elasticsearch索引
- 高效管理 Elasticsearch 中基於時間的索引Elasticsearch索引
- elasticsearch索引原理Elasticsearch索引
- ElasticSearch建立索引Elasticsearch索引
- Elasticsearch 7.x 之節點、叢集、分片及副本Elasticsearch
- Elasticsearch 學習索引Elasticsearch索引
- elasticsearch配置注入索引Elasticsearch索引
- 《從0開始學Elasticsearch》—叢集健康和索引管理Elasticsearch索引
- ElasticSearch 7.X版本19個常用的查詢語句Elasticsearch
- 剖析 Elasticsearch 的索引原理Elasticsearch索引
- elasticsearch之多索引查詢Elasticsearch索引
- elasticsearch如何設計索引Elasticsearch索引
- Elasticsearch(三):索引查詢Elasticsearch索引
- Elasticsearch 7.x Nested 巢狀型別查詢 | ES 乾貨Elasticsearch巢狀型別
- ElasticSearch 倒排索引(Inverted Index)| 什麼是倒排索引?Elasticsearch索引Index
- 使用Elasticsearch的動態索引和索引優化Elasticsearch索引優化
- 2 Day DBA-管理方案物件-關於方案物件管理許可權-管理索引-索引和效能物件索引
- 2 Day DBA-管理方案物件-關於方案物件管理許可權-管理索引-關於索引物件索引
- ElasticSearch分片互動過程(建立索引、刪除索引、查詢索引)Elasticsearch索引
- elasticsearch(三)----索引建立與刪除Elasticsearch索引
- 教你如何在 elasticsearch 中重建索引Elasticsearch索引
- Elasticsearch5.x建立索引(Java)ElasticsearchH5索引Java
- 2 Day DBA-管理方案物件-關於方案物件管理許可權-管理索引-列和函式索引物件索引函式
- Elasticsearch之索引模板index template與索引別名index aliasElasticsearch索引Index
- ElasticSearch系列2Elasticsearch
- Elasticsearch 索引的對映配置詳解Elasticsearch索引