Skip to content

Elasticsearch SQL

  • Added in Elasticseach 6.3

  • SQL query

  • Unresolved AST
  • Resolved plan
  • Optimized plan
  • Physical plan
  • Results

  • indexes turn into tables

  • documents turn into rows
curl -s "localhost:9200/_sql?format=txt" \
  --request GET \
  --header "Content-Type: application/json" \
  --data @sql.json
{
  "query": "DESCRIBE movies"
}
{
  "query": "SELECT title FROM movies LIMIT 10"
}
{
  "query": "SELECT title, year FROM movies WHERE year < 1920 ORDER BY year"
}

Translate sql to conventional json query

curl -s "localhost:9200/_sql/translate" \
  --request GET \
  --header "Content-Type: application/json" \
  --data @sql.json \
| jq .

Elasticsearch SQL CLI

  • /usr/share/elasticsearch/bin/elasticsearch-sql-cli