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

访问 SQL Elasticsearch

È un componente che consente di eseguire query simili a SQL su Elasticsearch in tempo reale della query. Puoi considerare Elasticsearch SQL come un traduttore che capisce sia SQL che Elasticsearch, e attraverso Funzionalità di Elasticsearch che consentono di leggere e elaborare dati in tempo reale in modo semplice.

Vantaggi di Elasticsearch SQL

  • Ha un'integrazione locale − Esegue ogni query in modo efficiente sui nodi relativi basati sullo storage sottostante.

  • Nessun componente esterno − Non richiede hardware, processi, runtime o librerie aggiuntivi per interrogare Elasticsearch.

  • Leggero ed efficiente − Contiene e rende pubblico SQL per eseguire ricerche full-text in tempo reale.

Esempio

PUT /schoollist/_bulk?refresh
   {"index":{"_id":"CBSE"}}
   {"name": "GleanDale", "Address": "Via Corte Junior", "data_inizio": "2011-06-02",
   "student_count": 561}
   {"index":{"_id": "ICSE"}}
   {"name": "Top-Notch", "Address": "Strada Principale di Gachibowli", "data_inizio": "1989-
   05-26", "student_count": 482}
   {"index":{"_id": "State Board"}}
   {"name": "Sunshine", "Address": "Via Principale", "data_inizio": "1965-06-01",
   "student_count": 604}

Eseguito il codice sopra, otteniamo la risposta seguente:

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

Query SQL

Esempio seguente mostra come costruire una query SQL-

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

Eseguito il codice sopra, otteniamo la risposta seguente:

Indirizzo             | nome          | data_inizio             | numero_di_studenti
--------------------+---------------+------------------------+---------------
Gachibowli Main Road | Top-Notch | 1989-05-26T00:00:00.000Z | 482
Main Street | Sunshine | 1965-06-01T00:00:00.000Z | 604

注意 −通过更改上面的 SQL 查询,您可以获得不同的结果集。