它是一個(gè)組件,允許對(duì) Elasticsearch 實(shí)時(shí)執(zhí)行類(lèi)似 sql 的查詢(xún)。您可以將 Elasticsearch SQL 看作是一個(gè)翻譯器,它同時(shí)理解 SQL 和 Elasticsearch,并且通過(guò) Elasticsearch 功能,可以方便地實(shí)時(shí)讀取和處理數(shù)據(jù)。
它具有本地集成 ?根據(jù)底層存儲(chǔ),對(duì)相關(guān)節(jié)點(diǎn)高效地執(zhí)行每個(gè)查詢(xún)。
沒(méi)有外部部件 ?不需要額外的硬件、進(jìn)程、運(yùn)行時(shí)或庫(kù)來(lái)查詢(xún)Elasticsearch。
輕量級(jí)和高效率 ?它包含并公開(kāi)了SQL,以便實(shí)時(shí)進(jìn)行適當(dāng)?shù)娜谋舅阉鳌?/p>
PUT /schoollist/_bulk?refresh {"index":{"_id": "CBSE"}} {"name": "GleanDale", "Address": "JR. Court Lane", "start_date": "2011-06-02", "student_count": 561} {"index":{"_id": "ICSE"}} {"name": "Top-Notch", "Address": "Gachibowli Main Road", "start_date": "1989- 05-26", "student_count": 482} {"index":{"_id": "State Board"}} {"name": "Sunshine", "Address": "Main Street", "start_date": "1965-06-01", "student_count": 604}
運(yùn)行上面的代碼后,我們得到如下所示的響應(yīng):
{ "took" : 277, "errors" : false, "items" : [ { "index" : { "_index" : "schoollist", "_type" : "_doc", "_id" : "CBSE", "_version" : 1, "result" : "created", "forced_refresh" : true, "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1, "status" : 201 } }, { "index" : { "_index" : "schoollist", "_type" : "_doc", "_id" : "ICSE", "_version" : 1, "result" : "created", "forced_refresh" : true, "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 1, "_primary_term" : 1, "status" : 201 } }, { "index" : { "_index" : "schoollist", "_type" : "_doc", "_id" : "State Board", "_version" : 1, "result" : "created", "forced_refresh" : true, "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 2, "_primary_term" : 1, "status" : 201 } } ] }
以下示例顯示了如何構(gòu)建SQL查詢(xún)-
POST /_sql?format=txt { "query": "SELECT * FROM schoollist WHERE start_date < '2000-01-01'" }
運(yùn)行上面的代碼后,我們得到如下所示的響應(yīng):
Address | name | start_date | student_count --------------------+---------------+------------------------+--------------- Gachibowli Main Road|Top-Notch |1989-05-26T00:00:00.000Z|482 Main Street |Sunshine |1965-06-01T00:00:00.000Z|604
Note ?通過(guò)更改上面的SQL查詢(xún),您可以獲得不同的結(jié)果集。