Lindorm搜尋引擎提供可視化使用者介面,您可以通過該介面使用RESTful介面訪問Lindorm搜尋引擎。本文介紹了如何通過Lindorm控制台登入UI介面並執行讀寫請求。
前提條件
操作步驟
登入UI介面
登入Lindorm管理主控台。
在頁面左上方,選擇執行個體所屬的地區。
在執行個體列表頁,單擊目標執行個體ID或者目標執行個體所在行操作列的管理。
在左側導覽列中,單擊搜尋引擎。
在UI訪問地區,單擊公網訪問或專用網路訪問登入叢集管理系統。
在彈出的登入頁面,輸入UI訪問地區中的預設使用者名和預設初始密碼。
說明首次訪問時,由於頁面資源載入的原因,需要稍作等待才能進入UI介面。
首次訪問必須使用擷取的預設使用者名和預設初始密碼登入搜尋UI訪問介面,後續登入可以使用預設使用者建立的其他使用者登入叢集管理UI。
讀寫操作
讀寫操作文法適配 ES API 7.x版本。
進入Dev Tools
單擊介面左上方的
表徵圖,開啟側邊欄,單擊。
進入Dev Tools,可通過RESTful介面訪問Lindorm搜尋引擎。

查看所有已建立索引
使用cat API,查看搜尋引擎中所有已建立的索引基本資料。
在路徑參數中加入參數v,頂部會顯示每一列對應的資訊名稱。
GET /_cat/indices?v返回結果:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open test2 test2 2 0 0 0 416b 416b
green open test3 test3 2 0 1 0 16.8kb 16.8kb
green open test1 test1 1 0 0 0 208b 208b
green open .kibana_1 .kibana_1 1 0 1 0 5.1kb 5.1kb建立索引
使用Create index API,建立索引。
在請求體中,可以指定索引的settings和mappings資訊。
settings:索引的配置,如:索引分區數(index.number_of_shards),資料從寫入到可見的最長間隔時間(index.refresh_interval)等。
mappings:索引的結構,如:索引中的欄位,每個欄位的類型等。
PUT /test { "settings": { "index.number_of_shards": 2, "index.refresh_interval": "10s" }, "mappings": { "properties": { "firstName": { "type": "keyword" }, "lastName": { "type": "keyword" } } } }返回結果:
{ "acknowledged": true, "shards_acknowledged": true, "index": "test" }
查看指定索引資訊
使用Get index API,查看指定索引的資訊,包括索引的settings和mappings資訊。
GET /test返回結果:
{ "test": { "aliases": {}, "mappings": { "properties": { "firstName": { "type": "keyword" }, "lastName": { "type": "keyword" } } }, "settings": { "index": { "search": { "slowlog": { "level": "DEBUG", "threshold": { "fetch": { "warn": "1s", "trace": "200ms", "debug": "500ms", "info": "800ms" }, "query": { "warn": "10s", "trace": "500ms", "debug": "1s", "info": "5s" } } } }, "refresh_interval": "10s", "indexing": { "slowlog": { "level": "DEBUG", "threshold": { "index": { "warn": "10s", "trace": "500ms", "debug": "2s", "info": "5s" } } } }, "number_of_shards": "2", "provided_name": "test4", "creation_date": "1722418296110", "number_of_replicas": "0", "uuid": "test4", "version": { "created": "136287927" } } } } }僅查看settings或mappings資訊,可以通過Get index settings API或Get mapping API來擷取。
以擷取settings資訊為例。
GET /test/_settings返回結果:
{ "test": { "settings": { "index": { "search": { "slowlog": { "level": "DEBUG", "threshold": { "fetch": { "warn": "1s", "trace": "200ms", "debug": "500ms", "info": "800ms" }, "query": { "warn": "10s", "trace": "500ms", "debug": "1s", "info": "5s" } } } }, "refresh_interval": "10s", "indexing": { "slowlog": { "level": "DEBUG", "threshold": { "index": { "warn": "10s", "trace": "500ms", "debug": "2s", "info": "5s" } } } }, "number_of_shards": "2", "provided_name": "test4", "creation_date": "1722418296110", "number_of_replicas": "0", "uuid": "test4", "version": { "created": "136287927" } } } } }
更新索引配置
使用Update index settings API可以更新索引中支援動態修改的配置項。
以修改index.refresh_interval配置為例,可以將資料從寫入到可見的間隔時間修改為1s(最短間隔為1s)。
PUT /test/_settings
{
"index": {
"refresh_interval": "1s"
}
}返回結果:
{
"acknowledged": true
}向索引中寫入資料
使用Index API,向索引中寫入資料。
使用PUT方法,需要顯式指定id。若指定id在索引中已存在,則會使用新寫入資料覆蓋已存在的資料。
以指定id是
1為例:PUT /test/_doc/1 { "firstName": "John", "lastName": "Smith" }返回結果:
{ "_index": "test", "_type": "_doc", "_id": "1", "_version": 1, "result": "created", "_shards": { "total": 1, "successful": 1, "failed": 0 }, "_seq_no": 0, "_primary_term": 1 }使用POST方法,可不指定id,Lindorm搜尋引擎會自動給該條資料產生id。
POST /test/_doc { "firstName": "Frank", "lastName": "Brown" }返回結果:
{ "_index": "test", "_type": "_doc", "_id": "b_MsCJEB3g4To6JSOeF6", "_version": 1, "result": "created", "_shards": { "total": 1, "successful": 1, "failed": 0 }, "_seq_no": 0, "_primary_term": 1 }Lindorm搜尋引擎會自動給該條資料產生id:
b_MsCJEB3g4To6JSOeF6。使用Update API,更新已有資料的部分欄位。其中,路徑參數中需要攜帶資料id,請求體中需要包含
doc參數。以指定id是
1,firstName更新為Lane為例:POST /test/_update/1 { "doc": { "firstName": "Lane" } }返回結果:
{ "_index": "test", "_type": "_doc", "_id": "1", "_version": 2, "result": "updated", "_shards": { "total": 1, "successful": 1, "failed": 0 }, "_seq_no": 1, "_primary_term": 1 }
查看索引資料
使用Search API,查看索引的資料。在請求體中,可以選擇指定查詢條件。
以指定lastName是
Smith為例:GET /test/_search { "query": { "match": { "lastName": "Smith" } } }返回結果:
{ "took": 4, "timed_out": false, "_shards": { "total": 2, "successful": 2, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 1, "relation": "eq" }, "max_score": 0.18232156, "hits": [ { "_index": "test", "_id": "1", "_score": 0.18232156, "_source": { "firstName": "Lane", "lastName": "Smith" } } ] } }使用Get API,可以查看指定id的資料。
以指定id是
1為例:GET /test/_doc/1返回結果:
{ "_index": "test", "_id": "1", "_version": 2, "_seq_no": 1, "_primary_term": 1, "found": true, "_source": { "firstName": "Lane", "lastName": "Smith" } }
刪除索引資料
使用Delete API,刪除索引中指定id的資料。
以指定id是1為例:
DELETE /test/_doc/1返回結果:
{
"_index": "test",
"_type": "_doc",
"_id": "1",
"_version": 3,
"result": "deleted",
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"_seq_no": 2,
"_primary_term": 1
}傳回值successful為1,代表已成功刪除指定資料。