Elasticsearch(009):es中index(索引)的新增、修改、刪除、關閉等操作
原創瘦子沒有夏天 發布於2020-01-03 18:31:38 閱讀數 17 收藏
展開
文章目錄
索引(Index)
1. 添加索引
2. 獲取索引
3. 修改索引
4. 刪除索引
5. 打開/關閉索引
6. 獲取所有索引列表
索引(Index)
本篇文章主要學習索引的相關操作。
1. 添加索引
PUT example
{
"settings" : {
"index" : {
"number_of_shards" : 2, #設置分片的數量,在集群中通常設置多個分片,表示一個索引庫將拆分成多片分別存儲不同的結點,提高了ES的處理能力和高可用性,這里設置為2。
"number_of_replicas" : 1 #設置副本的數量,設置副本是為了提高ES的高可靠性,這里設置成設置為1
}
}
}
返回值
{
"acknowledged" : true, #表示創建成功
"shards_acknowledged" : true,
"index" : "example"
}
當然還有不止一個參數針對Index,更多的可以參考這里。 todo
2. 獲取索引
GET example
返回值
{
"example" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1573387465030",
"number_of_shards" : "2",
"number_of_replicas" : "1",
"uuid" : "yw-ZmC4ATjeukZb6N-ub8A",
"version" : {
"created" : "6050499"
},
"provided_name" : "example"
}
}
}
}
上面的示例獲取名為的索引的信息example。需要指定索引,別名或通配符表達式。
通過使用_all或*作為索引,get index API也可以應用於多個索引,或者應用於所有索引。
3. 修改索引
修改example索引的max_result_window的值,調大一些。默認是10000。使用ES的人肯定知道其分頁在超過10000條數據后會報錯。
Result window is too large, from + size must be less than or equal to: [10000] but was [78020]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.
1
所以這里我們以此為例來動態修改其值,來解決這個問題。
PUT example/_settings
{
"index.max_result_window": 1000000000
}
返回結果
{
"acknowledged" : true
}
我們通過剛剛的查詢方法,獲取索引,來查看我們的修改操作是否已經生效。
4. 刪除索引
DELETE example
返回結果
{
"acknowledged" : true
}
這時我們通過查詢索引方法就會報錯。如下
{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index",
"index_uuid" : "_na_",
"resource.type" : "index_or_alias",
"resource.id" : "example",
"index" : "example"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index",
"index_uuid" : "_na_",
"resource.type" : "index_or_alias",
"resource.id" : "example",
"index" : "example"
},
"status" : 404
}
5. 打開/關閉索引
打開和關閉索引API允許先關閉索引,然后再打開索引。封閉索引幾乎沒有集群開銷(除了維護其元數據),並且被禁止進行讀/寫操作。可以打開一個封閉的索引,然后將通過正常的恢復過程。
REST端點為/{index}/_close和/{index}/_open。例如
#關閉索引
POST /example/_close
1
2
返回值
{
"acknowledged" : true
}
#打開索引
POST /example/_open
返回值
{
"acknowledged" : true,
"shards_acknowledged" : true
}
6. 獲取所有索引列表
#獲取所有索引列表
GET _all
其實創建索引時也可以同時創建映射,也可以后面添加創建。我們下一小節將研究映射的問題。
————————————————
版權聲明:本文為CSDN博主「瘦子沒有夏天」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/weixin_39723544/article/details/103825051