它是一個組件,允許對 Elasticsearch 實時執(zhí)行類似 sql 的查詢。您可以將 Elasticsearch SQL 看作是一個翻譯器,它同時理解 SQL 和 Elasticsearch,并且通過 Elasticsearch 功能,可以方便地實時讀取和處理數(shù)據(jù)。
它具有本地集成 ?根據(jù)底層存儲,對相關(guān)節(jié)點高效地執(zhí)行每個查詢。
沒有外部部件 ?不需要額外的硬件、進程、運行時或庫來查詢Elasticsearch。
輕量級和高效率 ?它包含并公開了SQL,以便實時進行適當?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}
運行上面的代碼后,我們得到如下所示的響應:
{ "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查詢-
POST /_sql?format=txt { "query": "SELECT * FROM schoollist WHERE start_date < '2000-01-01'" }
運行上面的代碼后,我們得到如下所示的響應:
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 ?通過更改上面的SQL查詢,您可以獲得不同的結(jié)果集。