這些API負責管理索引的所有方面,例如設置,別名,映射,索引模板。
該API可幫助您創(chuàng)建索引。當用戶將JSON對象傳遞給任何索引時,可以自動創(chuàng)建索引,也可以在此之前創(chuàng)建索引。要創(chuàng)建索引,您只需要發(fā)送帶有設置,映射和別名的PUT請求,或者僅發(fā)送不帶正文的簡單請求。
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或*刪除所有索引。
可以通過僅將get請求發(fā)送到一個或多個索引來調用此API。這將返回有關索引的信息。
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或*獲取所有索引的信息。
索引的存在可以通過僅向該索引發(fā)送get請求來確定。如果HTTP響應是200,則存在。如果是404,則不存在。
HEAD colleges
運行上面的代碼后,我們得到如下所示的輸出-
200-OK
您只需在網址末尾附加_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可幫助您提取有關特定索引的統(tǒng)計信息。您只需要在末尾發(fā)送帶有索引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 } }