Skip to content

Instantly share code, notes, and snippets.

@derickson
Created August 7, 2018 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derickson/5802182673869e8553d209756a24bf1d to your computer and use it in GitHub Desktop.
Save derickson/5802182673869e8553d209756a24bf1d to your computer and use it in GitHub Desktop.
## 1) Pull all records from index named fedeastsql
POST /_xpack/sql?format=txt
{
"query": "SELECT * FROM fedeastsql"
}
## 2) List all columns and datatype of this index
POST /_xpack/sql?format=txt
{
"query": "DESCRIBE fedeastsql"
}
## 3) Sort employees by start date
POST /_xpack/sql?format=txt
{
"query": "SELECT * FROM fedeastsql ORDER BY start_date DESC LIMIT 10"
}
## 4) Fetch all employees that live in Virginia
POST /_xpack/sql?format=txt
{
"query": "SELECT * FROM fedeastsql WHERE state = 'Virginia' "
}
## 5) Fetch all employees whose name start with the letter D
## Bonus) Translate SQL to Elasticsearch Query DSL
POST /_xpack/sql?format=txt
{
"query": "SELECT * FROM fedeastsql WHERE first_name LIKE 'D%' "
}
POST /_xpack/sql/translate
{
"query": "SELECT * FROM fedeastsql WHERE first_name LIKE 'D%' "
}
POST /_xpack/sql/translate
{
"query": "SELECT * FROM fedeastsql WHERE first_name LIKE 'D%' ",
"fetch_size": 10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment