Skip to content

Commit ea635d6

Browse files
authored
[DOCS] SQL: Add formal API docs (#75506)
Adds formal API docs for the following APIs: * Clear SQL cursor * SQL search * SQL translate Other changes: * Removes and redirects the "Supported REST parameters section." This is now covered in the SQL search API docs. * Updates a few related xrefs. Closes #75085
1 parent 984d5a1 commit ea635d6

File tree

15 files changed

+319
-118
lines changed

15 files changed

+319
-118
lines changed

docs/reference/redirects.asciidoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,4 +1632,10 @@ See <<field-usage-stats>>.
16321632
[role="exclude",id="security-api-enroll-kibana"]
16331633
=== Enroll {kib} API
16341634

1635-
See <<security-api-kibana-enrollment>>.
1635+
See <<security-api-kibana-enrollment>>.
1636+
1637+
[role="exclude",id="sql-rest-fields"]
1638+
=== Supported REST parameters for SQL search API
1639+
1640+
See the <<sql-search-api-request-body,request body parameters>> for the
1641+
<<sql-search-api,SQL search API>>.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[role="xpack"]
2+
[testenv="basic"]
3+
[[clear-sql-cursor-api]]
4+
=== Clear SQL cursor API
5+
++++
6+
<titleabbrev>Clear SQL cursor</titleabbrev>
7+
++++
8+
9+
Clears an <<sql-pagination,SQL search cursor>>.
10+
11+
////
12+
[source,console]
13+
----
14+
POST _sql
15+
{
16+
"query": "SELECT * FROM library ORDER BY page_count DESC",
17+
"fetch_size": 5
18+
}
19+
----
20+
// TEST[setup:library]
21+
////
22+
23+
[source,console]
24+
----
25+
POST _sql/close
26+
{
27+
"cursor": "sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWYUpOYklQMHhRUEtld3RsNnFtYU1hQQ==:BAFmBGRhdGUBZgVsaWtlcwFzB21lc3NhZ2UBZgR1c2Vy9f///w8="
28+
}
29+
----
30+
// TEST[continued]
31+
// TEST[s/sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWYUpOYklQMHhRUEtld3RsNnFtYU1hQQ==:BAFmBGRhdGUBZgVsaWtlcwFzB21lc3NhZ2UBZgR1c2Vy9f\/\/\/w8=/$body.cursor/]
32+
33+
[[clear-sql-cursor-api-request]]
34+
==== {api-request-title}
35+
36+
`POST _sql/close`
37+
38+
[[clear-sql-cursor-api-limitations]]
39+
===== Limitations
40+
41+
See <<sql-limitations>>.
42+
43+
[role="child_attributes"]
44+
[[clear-sql-cursor-api-request-body]]
45+
==== {api-request-body-title}
46+
47+
`cursor`::
48+
(Required, string) Cursor to clear.

docs/reference/sql/apis/get-async-sql-search-api.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ Defaults to no timeout, meaning the request waits for complete search results.
6060
[[get-async-sql-search-api-response-body]]
6161
==== {api-response-body-title}
6262

63-
The get async SQL search API returns the same response body as the SQL search
64-
API.
63+
The get async SQL search API returns the same response body as the
64+
<<sql-search-api-response-body,SQL search API>>.

docs/reference/sql/apis/sql-apis.asciidoc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@
33
[[sql-apis]]
44
== SQL APIs
55

6-
NOTE: This list of SQL APIs is incomplete. We're working to add more.
7-
86
{es}'s SQL APIs let you run SQL queries on {es} indices and data streams.
97
For an overview of {es}'s SQL features and related tutorials, see <<xpack-sql>>.
108

9+
* <<sql-search-api>>
10+
* <<clear-sql-cursor-api>>
1111
* <<get-async-sql-search-api>>
1212
* <<get-async-sql-search-status-api>>
1313
* <<delete-async-sql-search-api>>
14+
* <<sql-translate-api>>
15+
16+
include::clear-sql-cursor-api.asciidoc[]
1417

1518
include::delete-async-sql-search-api.asciidoc[]
1619

1720
include::get-async-sql-search-api.asciidoc[]
1821

19-
include::get-async-sql-search-status-api.asciidoc[]
22+
include::get-async-sql-search-status-api.asciidoc[]
23+
24+
include::sql-search-api.asciidoc[]
25+
26+
include::sql-translate-api.asciidoc[]
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
[role="xpack"]
2+
[testenv="basic"]
3+
[[sql-search-api]]
4+
=== SQL search API
5+
++++
6+
<titleabbrev>SQL search</titleabbrev>
7+
++++
8+
9+
Returns results for an <<sql-rest-overview,SQL search>>.
10+
11+
[source,console]
12+
----
13+
POST _sql?format=txt
14+
{
15+
"query": "SELECT * FROM library ORDER BY page_count DESC LIMIT 5"
16+
}
17+
----
18+
// TEST[setup:library]
19+
20+
[[sql-search-api-request]]
21+
==== {api-request-title}
22+
23+
`GET _sql`
24+
25+
`POST _sql`
26+
27+
[[sql-search-api-prereqs]]
28+
==== {api-prereq-title}
29+
30+
* If the {es} {security-features} are enabled, you must have the `read`
31+
<<privileges-list-indices,index privilege>> for the data stream, index,
32+
or alias you search.
33+
34+
[[sql-search-api-limitations]]
35+
===== Limitations
36+
37+
See <<sql-limitations>>.
38+
39+
[[search-api-query-params]]
40+
==== {api-query-parms-title}
41+
42+
`delimiter`::
43+
(Optional, string) Separator for CSV results. Defaults to `,`. The API only
44+
supports this parameter for CSV responses.
45+
46+
`format`::
47+
(Optional, string) Format for the response. For valid values, see
48+
<<sql-rest-format>>.
49+
+
50+
You can also specify a format using the `Accept` HTTP header. If you specify
51+
both this parameter and the `Accept` HTTP header, this parameter takes
52+
precedence.
53+
54+
[role="child_attributes"]
55+
[[sql-search-api-request-body]]
56+
==== {api-request-body-title}
57+
58+
`columnar`::
59+
(Optional, Boolean) If `true`, returns results in a columnar format. Defaults to
60+
`false`. The API only supports this parameter for CBOR, JSON, SMILE, and YAML
61+
responses. See <<sql-rest-columnar>>.
62+
63+
`cursor`::
64+
(Optional, string) <<sql-pagination,Cursor>> used to retrieve a set of paginated
65+
results. If you specify a `cursor`, the API only uses the `columnar` and
66+
`time_zone` request body parameters. It ignores other request body parameters.
67+
68+
[[sql-search-api-fetch-size]]
69+
`fetch_size`::
70+
(Optional, integer) Maximum number of rows to return in the response. Defaults
71+
to `1000`.
72+
73+
[[sql-search-api-field-multi-value-leniency]]
74+
`field_multi_value_leniency`::
75+
(Optional, Boolean) If `false`, the API returns an error for fields containing
76+
<<array,array values>>. If `true`, the API returns the first value from the
77+
array with no guarantee of consistent results. Defaults to `false`.
78+
79+
`filter`::
80+
(Optional, object) <<query-dsl,Query DSL>> used to filter documents for the SQL
81+
search. See <<sql-rest-filtering>>.
82+
83+
`index_include_frozen`::
84+
(Optional, Boolean) If `true`, the search can run on frozen indices. Defaults to
85+
`false`.
86+
87+
`keep_alive`::
88+
(Optional, <<time-units,time value>>) Retention period for an
89+
<<sql-async,async>> or <<sql-store-searches,saved synchronous search>>. Defaults
90+
to `5d` (five days).
91+
92+
`keep_on_completion`::
93+
(Optional, Boolean) If `true`, {es} <<sql-store-searches,stores synchronous
94+
searches>> if you also specify the `wait_for_completion_timeout` parameter. If
95+
`false`, {es} only stores <<sql-async,async searches>> that don't finish before
96+
the `wait_for_completion_timeout`. Defaults to `false`.
97+
98+
`page_timeout`::
99+
(Optional, <<time-units,time value>>) Timeout before a
100+
<<sql-pagination,pagination request>> fails. Defaults to `45s` (45 seconds).
101+
102+
`params`::
103+
(Optional, array) Values for parameters in the `query`. For syntax, see
104+
<<sql-rest-params>>.
105+
106+
`query`::
107+
(Required, object) SQL query to run. For syntax, see <<sql-spec>>.
108+
109+
`request_timeout`::
110+
(Optional, <<time-units,time value>>) Timeout before the request fails. Defaults
111+
to `90s` (90 seconds).
112+
113+
include::{es-repo-dir}/search/search.asciidoc[tag=runtime-mappings-def]
114+
115+
[[sql-search-api-time-zone]]
116+
`time_zone`::
117+
(Optional, string) ISO-8601 time zone ID for the search. Several
118+
<<sql-functions-datetime,SQL date/time functions>> use this time zone. Defaults
119+
to `Z` (UTC).
120+
121+
`wait_for_completion_timeout`::
122+
(Optional, <<time-units,time value>>) Period to wait for complete results.
123+
Defaults to no timeout, meaning the request waits for complete search results.
124+
If the search doesn’t finish within this period, the search becomes
125+
<<sql-async,async>>.
126+
+
127+
To <<sql-store-searches,save a synchronous search>>, you must specify this
128+
parameter and the `keep_on_completion` parameter.
129+
130+
[role="child_attributes"]
131+
[[sql-search-api-response-body]]
132+
==== {api-response-body-title}
133+
134+
The SQL search API supports <<sql-rest-format,multiple response formats>>. Most
135+
response formats use a tabular layout. JSON responses contain the following
136+
properties:
137+
138+
`id`::
139+
(string) Identifier for the search. This value is only returned for
140+
<<sql-async,async>> and <<sql-store-searches,saved synchronous searches>>. For
141+
CSV, TSV, and TXT responses, this value is returned in the `Async-ID` HTTP
142+
header.
143+
144+
`is_running`::
145+
(Boolean) If `true`, the search is still running. If `false`, the search has
146+
finished. This value is only returned for <<sql-async,async>> and
147+
<<sql-store-searches,saved synchronous searches>>. For CSV, TSV, and TXT
148+
responses, this value is returned in the `Async-partial` HTTP header.
149+
150+
`is_partial`::
151+
(Boolean) If `true`, the response does not contain complete search results. If
152+
`is_partial` is `true` and `is_running` is `true`, the search is still running.
153+
If `is_partial` is `true` but `is_running` is `false`, the results are partial
154+
due to a failure or timeout.
155+
+
156+
This value is only returned for <<sql-async,async>> and
157+
<<sql-store-searches,saved synchronous searches>>. For CSV, TSV, and TXT
158+
responses, this value is returned in the `Async-partial` HTTP header.
159+
160+
`rows`::
161+
(array of arrays)
162+
Values for the search results.
163+
164+
`columns`::
165+
(array of objects)
166+
Column headings for the search results. Each object is a column.
167+
+
168+
.Properties of `columns` objects
169+
[%collapsible%open]
170+
====
171+
`name`::
172+
(string) Name of the column.
173+
174+
`type`::
175+
(string) Data type for the column.
176+
====
177+
178+
`cursor`::
179+
(string) <<sql-pagination,Cursor>> for the next set of paginated results. For
180+
CSV, TSV, and TXT responses, this value is returned in the `Cursor` HTTP header.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[role="xpack"]
2+
[testenv="basic"]
3+
[[sql-translate-api]]
4+
=== SQL translate API
5+
++++
6+
<titleabbrev>SQL translate</titleabbrev>
7+
++++
8+
9+
Translates an <<sql-search-api,SQL search>> into a <<search-search,search API>>
10+
request containing <<query-dsl,Query DSL>>. See <<sql-translate>>.
11+
12+
[source,console]
13+
----
14+
POST _sql/translate
15+
{
16+
"query": "SELECT * FROM library ORDER BY page_count DESC",
17+
"fetch_size": 10
18+
}
19+
----
20+
// TEST[setup:library]
21+
22+
[[sql-translate-api-request]]
23+
==== {api-request-title}
24+
25+
`GET _sql/translate`
26+
27+
`POST _sql/translate`
28+
29+
[[sql-translate-api-prereqs]]
30+
==== {api-prereq-title}
31+
32+
* If the {es} {security-features} are enabled, you must have the `read`
33+
<<privileges-list-indices,index privilege>> for the data stream, index,
34+
or alias you search.
35+
36+
[[sql-translate-api-limitations]]
37+
===== Limitations
38+
39+
See <<sql-limitations>>.
40+
41+
[role="child_attributes"]
42+
[[sql-translate-api-request-body]]
43+
==== {api-request-body-title}
44+
45+
The SQL translate API accepts the same request body parameters as the
46+
<<sql-search-api-request-body,SQL search API>>, excluding `cursor`.
47+
48+
[role="child_attributes"]
49+
[[sql-translate-api-response-body]]
50+
==== {api-response-body-title}
51+
52+
The SQL translate API returns the same response body as the
53+
<<search-search,search API>>.

docs/reference/sql/endpoints/odbc/configuration.asciidoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ timeout.
220220
* Max page size (rows)
221221
+
222222
The maximum number of rows that {es-sql} server should send the driver for one
223-
page. This corresponds to {es-sql}'s request parameter `fetch_size` (see
224-
<<sql-rest-fields>>). The value 0 means server default.
223+
page. This corresponds to the SQL search API's
224+
<<sql-search-api-fetch-size,`fetch_size`>> parameter. A `0` value indicates a
225+
server default.
225226
+
226227
* Max page length (MB)
227228
+
@@ -314,8 +315,9 @@ multi-value field is queried. In case this is set and the server encounters
314315
such a field, it will pick a value in the set - without any guarantees of what
315316
that will be, but typically the first in natural ascending order - and return
316317
it as the value for the column. If not set, the server will return an error.
317-
This corresponds to {es-sql}'s request parameter `field_multi_value_leniency`
318-
(see <<sql-rest-fields>>).
318+
This corresponds to the SQL search API's
319+
<<sql-search-api-field-multi-value-leniency,`field_multi_value_leniency`>>
320+
parameter.
319321
+
320322
* Include frozen indices
321323
+

0 commit comments

Comments
 (0)