2018-06-22 18:40:25 -04:00
|
|
|
[role="xpack"]
|
|
|
|
[testenv="basic"]
|
2017-12-13 10:19:31 -05:00
|
|
|
[[sql-translate]]
|
|
|
|
== SQL Translate API
|
|
|
|
|
|
|
|
The SQL Translate API accepts SQL in a JSON document and translates it
|
2019-02-15 14:15:40 -05:00
|
|
|
into native {es} queries. For example:
|
2017-12-13 10:19:31 -05:00
|
|
|
|
2019-09-05 10:11:25 -04:00
|
|
|
[source,console]
|
2017-12-13 10:19:31 -05:00
|
|
|
--------------------------------------------------
|
2018-11-27 22:16:21 -05:00
|
|
|
POST /_sql/translate
|
2017-12-13 10:19:31 -05:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"query": "SELECT * FROM library ORDER BY page_count DESC",
|
|
|
|
"fetch_size": 10
|
2017-12-13 10:19:31 -05:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[setup:library]
|
|
|
|
|
|
|
|
Which returns:
|
|
|
|
|
2019-09-06 09:22:08 -04:00
|
|
|
[source,console-result]
|
2017-12-13 10:19:31 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"size": 10,
|
|
|
|
"docvalue_fields": [
|
|
|
|
{
|
|
|
|
"field": "release_date",
|
|
|
|
"format": "epoch_millis"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"_source": {
|
|
|
|
"includes": [
|
|
|
|
"author",
|
|
|
|
"name",
|
|
|
|
"page_count"
|
2017-12-13 10:19:31 -05:00
|
|
|
],
|
2020-07-21 15:49:58 -04:00
|
|
|
"excludes": []
|
|
|
|
},
|
|
|
|
"sort": [
|
|
|
|
{
|
|
|
|
"page_count": {
|
|
|
|
"order": "desc",
|
|
|
|
"missing": "_first",
|
|
|
|
"unmapped_type": "short"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2017-12-13 10:19:31 -05:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
Which is the request that SQL will run to provide the results.
|
2020-07-31 12:40:40 -04:00
|
|
|
In this case, SQL will use the <<scroll-search-results,scroll>>
|
2017-12-13 10:19:31 -05:00
|
|
|
API. If the result contained an aggregation then SQL would use
|
|
|
|
the normal <<search-request-body,search>> API.
|
|
|
|
|
|
|
|
The request body accepts all of the <<sql-rest-fields,fields>> that
|
|
|
|
the <<sql-rest,SQL REST API>> accepts except `cursor`.
|