Overview

The SQL REST API accepts SQL in a JSON document, executes it, and returns the results. For example:

  1. POST /_sql?format=txt
  2. {
  3. "query": "SELECT * FROM library ORDER BY page_count DESC LIMIT 5"
  4. }

Which returns:

  1. author | name | page_count | release_date
  2. -----------------+--------------------+---------------+------------------------
  3. Peter F. Hamilton|Pandora's Star |768 |2004-03-02T00:00:00.000Z
  4. Vernor Vinge |A Fire Upon the Deep|613 |1992-06-01T00:00:00.000Z
  5. Frank Herbert |Dune |604 |1965-06-01T00:00:00.000Z
  6. Alastair Reynolds|Revelation Space |585 |2000-03-15T00:00:00.000Z
  7. James S.A. Corey |Leviathan Wakes |561 |2011-06-02T00:00:00.000Z

Using Kibana Console

If you are using Kibana Console (which is highly recommended), take advantage of the triple quotes """ when creating the query. This not only automatically escapes double quotes (") inside the query string but also support multi-line as shown below: console triple quotes