English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Elasticsearch SQLアクセス

コンポーネントであり、Elasticsearchに対してリアルタイムでSQLに似た のクエリです。Elasticsearch SQLは翻訳器であり、SQLとElasticsearchの両方を理解し、 Elasticsearch 功能,可以方便地实时读取和处理数据。

Elasticsearch SQL的优点

  • 它具有本地集成 −根据底层存储,对相关节点高效地执行每个查询。

  • 没有外部部件 −不需要额外的硬件、进程、运行时或库来查询Elasticsearch。

  • 轻量级和高效率 −它包含并公开了SQL,以便实时进行适当的全文本搜索。

实例

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
         }
      }
   ]
}

SQL查询

以下示例显示了如何构建SQL查询-

POST /_sql?format=txt
{
   "query": "SELECT * FROM schoollist WHERE start_date < ''2000-01-01"
}

上記のコードを実行すると、以下のような応答を得ることができます:

住所             | 名前          | 開始日             | 学生数
--------------------+---------------+------------------------+---------------
Gachibowli Main Road|Top-Notch      |1989-05-26T00:00:00.000Z|482
Main Street         |Sunshine       |1965-06-01T00:00:00.000Z|604

ノート −上記のSQLクエリを変更することで、異なる結果セットを取得できます。