- Elasticsearch 教程
- Elasticsearch - 首頁
- Elasticsearch - 基本概念
- Elasticsearch - 安裝
- Elasticsearch - 資料填充
- 版本遷移
- Elasticsearch - API 約定
- Elasticsearch - 文件API
- Elasticsearch - 搜尋API
- Elasticsearch - 聚合
- Elasticsearch - 索引API
- Elasticsearch - CAT API
- Elasticsearch - 叢集API
- Elasticsearch - 查詢DSL
- Elasticsearch - 對映
- Elasticsearch - 分析
- Elasticsearch - 模組
- Elasticsearch - 索引模組
- Elasticsearch - Ingest 節點
- Elasticsearch - 索引生命週期管理
- Elasticsearch - SQL訪問
- Elasticsearch - 監控
- Elasticsearch - 資料彙總
- Elasticsearch - 凍結索引
- Elasticsearch - 測試
- Elasticsearch - Kibana 儀表盤
- Elasticsearch - 按欄位過濾
- Elasticsearch - 資料表
- Elasticsearch - 地區地圖
- Elasticsearch - 餅圖
- Elasticsearch - 面積圖和條形圖
- Elasticsearch - 時間序列
- Elasticsearch - 詞雲
- Elasticsearch - 熱力圖
- Elasticsearch - Canvas
- Elasticsearch - 日誌UI
- Elasticsearch 有用資源
- Elasticsearch - 快速指南
- Elasticsearch - 有用資源
- Elasticsearch - 討論
Elasticsearch - 索引API
這些API負責管理索引的所有方面,例如設定、別名、對映和索引模板。
建立索引
此API幫助您建立索引。當用戶將JSON物件傳遞到任何索引時,可以自動建立索引,也可以在此之前建立索引。要建立索引,您只需要傳送一個帶有設定、對映和別名或只是一個簡單的無正文請求的PUT請求。
PUT colleges
執行以上程式碼後,我們將得到如下所示的輸出:
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "colleges"
}
我們也可以向以上命令新增一些設定:
PUT colleges
{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}
}
執行以上程式碼後,我們將得到如下所示的輸出:
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "colleges"
}
刪除索引
此API幫助您刪除任何索引。您只需要傳遞一個帶有該特定索引名稱的刪除請求。
DELETE /colleges
您可以只使用 _all 或 * 刪除所有索引。
獲取索引
此API可以透過向一個或多個索引發送GET請求來呼叫。這將返回有關索引的資訊。
GET colleges
執行以上程式碼後,我們將得到如下所示的輸出:
{
"colleges" : {
"aliases" : {
"alias_1" : { },
"alias_2" : {
"filter" : {
"term" : {
"user" : "pkay"
}
},
"index_routing" : "pkay",
"search_routing" : "pkay"
}
},
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1556245406616",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "3ExJbdl2R1qDLssIkwDAug",
"version" : {
"created" : "7000099"
},
"provided_name" : "colleges"
}
}
}
}
您可以使用 _all 或 * 獲取所有索引的資訊。
索引是否存在
可以透過向該索引發送GET請求來確定索引是否存在。如果HTTP響應為200,則表示存在;如果為404,則表示不存在。
HEAD colleges
執行以上程式碼後,我們將得到如下所示的輸出:
200-OK
索引設定
您可以透過在URL末尾附加 _settings 關鍵字來獲取索引設定。
GET /colleges/_settings
執行以上程式碼後,我們將得到如下所示的輸出:
{
"colleges" : {
"settings" : {
"index" : {
"creation_date" : "1556245406616",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "3ExJbdl2R1qDLssIkwDAug",
"version" : {
"created" : "7000099"
},
"provided_name" : "colleges"
}
}
}
}
索引統計資訊
此API幫助您提取有關特定索引的統計資訊。您只需要傳送一個帶有索引URL和 _stats 關鍵字的GET請求。
GET /_stats
執行以上程式碼後,我們將得到如下所示的輸出:
………………………………………………
},
"request_cache" : {
"memory_size_in_bytes" : 849,
"evictions" : 0,
"hit_count" : 1171,
"miss_count" : 4
},
"recovery" : {
"current_as_source" : 0,
"current_as_target" : 0,
"throttle_time_in_millis" : 0
}
} ………………………………………………
重新整理
索引的重新整理過程確保當前僅持久儲存在事務日誌中的任何資料也永久持久儲存在Lucene中。這減少了恢復時間,因為在開啟Lucene索引後,不需要從事務日誌中重新索引該資料。
POST colleges/_flush
執行以上程式碼後,我們將得到如下所示的輸出:
{
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
}
}
廣告