Skip to content

Commit 610dde0

Browse files
jrodewigelasticsearchmachine
authored andcommitted
[DOCS] Document async SQL APIs (elastic#75078)
Adds formal API docs and JSON specs for the following APIs: * Get async SQL search * Get async SQL search status * Delete async SQL search Closes elastic#74845
1 parent 91390d7 commit 610dde0

File tree

9 files changed

+319
-10
lines changed

9 files changed

+319
-10
lines changed

docs/reference/rest-api/index.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ not be included yet.
4141
* <<security-api,Security APIs>>
4242
* <<snapshot-restore-apis,Snapshot and restore APIs>>
4343
* <<snapshot-lifecycle-management-api,Snapshot lifecycle management APIs>>
44+
* <<sql-apis,SQL APIs>>
4445
* <<transform-apis,{transform-cap} APIs>>
4546
* <<usage-api,Usage API>>
4647
* <<watcher-api,Watcher APIs>>
@@ -77,6 +78,7 @@ include::{es-repo-dir}/searchable-snapshots/apis/searchable-snapshots-apis.ascii
7778
include::{xes-repo-dir}/rest-api/security.asciidoc[]
7879
include::{es-repo-dir}/snapshot-restore/apis/snapshot-restore-apis.asciidoc[]
7980
include::{es-repo-dir}/slm/apis/slm-api.asciidoc[]
81+
include::{es-repo-dir}/sql/apis/sql-apis.asciidoc[]
8082
include::{es-repo-dir}/transform/apis/index.asciidoc[]
8183
include::usage.asciidoc[]
8284
include::{xes-repo-dir}/rest-api/watcher.asciidoc[]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[role="xpack"]
2+
[testenv="basic"]
3+
[[delete-async-sql-search-api]]
4+
=== Delete async SQL search API
5+
++++
6+
<titleabbrev>Delete async SQL search</titleabbrev>
7+
++++
8+
9+
Deletes an <<sql-async,async SQL search>> or a <<sql-store-searches,stored
10+
synchronous SQL search>>. If the search is still running, the API cancels it.
11+
12+
[source,console]
13+
----
14+
DELETE /_sql/async/delete/FkpMRkJGS1gzVDRlM3g4ZzMyRGlLbkEaTXlJZHdNT09TU2VTZVBoNDM3cFZMUToxMDM=
15+
----
16+
// TEST[skip: no access to search ID]
17+
18+
[[delete-async-sql-search-api-request]]
19+
==== {api-request-title}
20+
21+
`DELETE /_sql/async/delete/<search_id>`
22+
23+
[[delete-async-sql-search-api-prereqs]]
24+
==== {api-prereq-title}
25+
26+
* If the {es} {security-features} are enabled, only the following users can
27+
use this API to delete a search:
28+
29+
** Users with the `cancel_task` <<privileges-list-cluster,cluster privilege>>
30+
** The user who first submitted the search
31+
32+
[[delete-async-sql-search-api-limitations]]
33+
===== Limitations
34+
35+
See <<sql-limitations>>.
36+
37+
[[delete-async-sql-search-api-path-params]]
38+
==== {api-path-parms-title}
39+
40+
`<search_id>`::
41+
(Required, string) Identifier for the search.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[role="xpack"]
2+
[testenv="basic"]
3+
[[get-async-sql-search-api]]
4+
=== Get async SQL search API
5+
++++
6+
<titleabbrev>Get async SQL search</titleabbrev>
7+
++++
8+
9+
Returns results for an <<sql-async,async SQL search>> or a
10+
<<sql-store-searches,stored synchronous SQL search>>.
11+
12+
[source,console]
13+
----
14+
GET _sql/async/FmdMX2pIang3UWhLRU5QS0lqdlppYncaMUpYQ05oSkpTc3kwZ21EdC1tbFJXQToxOTI=?format=json
15+
----
16+
// TEST[skip: no access to search ID]
17+
18+
[[get-async-sql-search-api-request]]
19+
==== {api-request-title}
20+
21+
`GET _sql/async/<search_id>`
22+
23+
[[get-async-sql-search-api-prereqs]]
24+
==== {api-prereq-title}
25+
26+
* If the {es} {security-features} are enabled, only the user who first submitted
27+
the SQL search can retrieve the search using this API.
28+
29+
[[get-async-sql-search-api-limitations]]
30+
===== Limitations
31+
32+
See <<sql-limitations>>.
33+
34+
[[get-async-sql-search-api-path-params]]
35+
==== {api-path-parms-title}
36+
37+
`<search_id>`::
38+
(Required, string) Identifier for the search.
39+
40+
[[get-async-sql-search-api-query-params]]
41+
==== {api-query-parms-title}
42+
43+
`delimiter`::
44+
(Optional, string) Separator for CSV results. Defaults to `,`. The API only
45+
supports this parameter for CSV responses.
46+
47+
`format`::
48+
(Required, string) Format for the response. You must specify a format using this
49+
parameter or the `Accept` HTTP header. If you specify both, the API uses this
50+
parameter. For valid values, see <<sql-rest-format>>.
51+
52+
`keep_alive`::
53+
(Optional, <<time-units,time value>>) Retention period for the search and its
54+
results. Defaults to the `keep_alive` period for the original SQL search.
55+
56+
`wait_for_completion_timeout`::
57+
(Optional, <<time-units,time value>>) Period to wait for complete results.
58+
Defaults to no timeout, meaning the request waits for complete search results.
59+
60+
[[get-async-sql-search-api-response-body]]
61+
==== {api-response-body-title}
62+
63+
The get async SQL search API returns the same response body as the SQL search
64+
API.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
[role="xpack"]
2+
[testenv="basic"]
3+
[[get-async-sql-search-status-api]]
4+
=== Get async SQL search status API
5+
++++
6+
<titleabbrev>Get async SQL search status</titleabbrev>
7+
++++
8+
9+
Returns the current status of an <<sql-async,async SQL search>> or a
10+
<<sql-store-searches,stored synchronous SQL search>>.
11+
12+
[source,console]
13+
----
14+
GET _sql/async/status/FmdMX2pIang3UWhLRU5QS0lqdlppYncaMUpYQ05oSkpTc3kwZ21EdC1tbFJXQToxOTI=?format=json
15+
----
16+
// TEST[skip: no access to search ID]
17+
18+
[[get-async-sql-search-status-api-request]]
19+
==== {api-request-title}
20+
21+
`GET _sql/async/status/<search_id>`
22+
23+
[[get-async-sql-search-status-api-prereqs]]
24+
==== {api-prereq-title}
25+
26+
* If the {es} {security-features} are enabled, you must have the `monitor`
27+
<<privileges-list-cluster,cluster privilege>> to use this API.
28+
29+
[[get-async-sql-search-status-api-limitations]]
30+
===== Limitations
31+
32+
See <<sql-limitations>>.
33+
34+
[[get-async-sql-search-status-api-path-params]]
35+
==== {api-path-parms-title}
36+
37+
`<search_id>`::
38+
(Required, string) Identifier for the search.
39+
40+
[role="child_attributes"]
41+
[[get-async-sql-search-status-api-response-body]]
42+
==== {api-response-body-title}
43+
44+
`id`::
45+
(string) Identifier for the search.
46+
47+
`is_running`::
48+
(Boolean) If `true`, the search is still running. If `false`, the
49+
search has finished.
50+
51+
`is_partial`::
52+
(Boolean) If `true`, the response does not contain complete search results. If
53+
`is_partial` is `true` and `is_running` is `true`, the search is still running.
54+
If `is_partial` is `true` but `is_running` is `false`, the results are partial
55+
due to a failure or timeout.
56+
57+
`start_time_in_millis`::
58+
(integer) Timestamp, in milliseconds since the Unix epoch, when the search
59+
started. The API only returns this property for running searches.
60+
61+
`expiration_time_in_millis`::
62+
(integer) Timestamp, in milliseconds since the Unix epoch, when {es} will delete
63+
the search and its results, even if the search is still running.
64+
65+
`completion_status`::
66+
(integer) HTTP status code for the search. The API only returns this property
67+
for completed searches.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[role="xpack"]
2+
[testenv="basic"]
3+
[[sql-apis]]
4+
== SQL APIs
5+
6+
NOTE: This list of SQL APIs is incomplete. We're working to add more.
7+
8+
{es}'s SQL APIs let you run SQL queries on {es} indices and data streams.
9+
For an overview of {es}'s SQL features and related tutorials, see <<xpack-sql>>.
10+
11+
* <<get-async-sql-search-api>>
12+
* <<get-async-sql-search-status-api>>
13+
* <<delete-async-sql-search-api>>
14+
15+
include::delete-async-sql-search-api.asciidoc[]
16+
17+
include::get-async-sql-search-api.asciidoc[]
18+
19+
include::get-async-sql-search-status-api.asciidoc[]

docs/reference/sql/endpoints/rest.asciidoc

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ For CSV, TSV, and TXT responses, the API returns these values in the respective
610610
// TESTRESPONSE[s/"is_partial": true/"is_partial": $body.is_partial/]
611611
// TESTRESPONSE[s/"is_running": true/"is_running": $body.is_running/]
612612

613-
To check the progress of an async search, use the search ID with the get async
614-
SQL search status API.
613+
To check the progress of an async search, use the search ID with the
614+
<<get-async-sql-search-status-api,get async SQL search status API>>.
615615

616616
[source,console]
617617
----
@@ -636,9 +636,10 @@ complete results.
636636
// TESTRESPONSE[s/FnR0TDhyWUVmUmVtWXRWZER4MXZiNFEad2F5UDk2ZVdTVHV1S0xDUy00SklUdzozMTU=/$body.id/]
637637
// TESTRESPONSE[s/"expiration_time_in_millis": 1611690295000/"expiration_time_in_millis": $body.expiration_time_in_millis/]
638638

639-
To get the results, use the search ID with the get async SQL search API. If the
640-
search is still running, specify how long you’d like to wait using
641-
`wait_for_completion_timeout`. You can also specify the response `format`.
639+
To get the results, use the search ID with the <<get-async-sql-search-api,get
640+
async SQL search API>>. If the search is still running, specify how long you’d
641+
like to wait using `wait_for_completion_timeout`. You can also specify the
642+
response `format`.
642643

643644
[source,console]
644645
----
@@ -676,8 +677,9 @@ GET _sql/async/FmdMX2pIang3UWhLRU5QS0lqdlppYncaMUpYQ05oSkpTc3kwZ21EdC1tbFJXQToxO
676677
----
677678
// TEST[skip: no access to search ID]
678679

679-
Use the delete async SQL search API to delete an async search before the
680-
`keep_alive` period ends. If the search is still running, {es} cancels it.
680+
Use the <<delete-async-sql-search-api,delete async SQL search API>> to delete an
681+
async search before the `keep_alive` period ends. If the search is still
682+
running, {es} cancels it.
681683

682684
[source,console]
683685
----
@@ -725,12 +727,13 @@ returned complete results.
725727
// TESTRESPONSE[s/"columns": \.\.\./"columns": $body.columns/]
726728
// TESTRESPONSE[s/"cursor": \.\.\./"cursor": $body.cursor/]
727729

728-
You can get the same results later using the search ID with the get async SQL
729-
search API.
730+
You can get the same results later using the search ID with the
731+
<<get-async-sql-search-api,get async SQL search API>>.
730732

731733
Saved synchronous searches are still subject to the `keep_alive` retention
732734
period. When this period ends, {es} deletes the search results. You can also
733-
delete saved searches using the delete async SQL search API.
735+
delete saved searches using the <<delete-async-sql-search-api,delete async SQL
736+
search API>>.
734737

735738
[[sql-rest-fields]]
736739
=== Supported REST parameters
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"sql.delete_async": {
3+
"documentation": {
4+
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-async-sql-search-api.html",
5+
"description": "Deletes an async SQL search or a stored synchronous SQL search. If the search is still running, the API cancels it."
6+
},
7+
"stability": "stable",
8+
"visibility": "public",
9+
"headers": {
10+
"accept": [
11+
"application/json"
12+
]
13+
},
14+
"url": {
15+
"paths": [
16+
{
17+
"path": "/_sql/async/delete/{id}",
18+
"methods": [
19+
"DELETE"
20+
],
21+
"parts": {
22+
"id": {
23+
"type": "string",
24+
"description": "The async search ID"
25+
}
26+
}
27+
}
28+
]
29+
}
30+
}
31+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"sql.get_async": {
3+
"documentation": {
4+
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html",
5+
"description": "Returns the current status and available results for an async SQL search or stored synchronous SQL search"
6+
},
7+
"stability": "stable",
8+
"visibility": "public",
9+
"headers": {
10+
"accept": [
11+
"application/json"
12+
]
13+
},
14+
"url": {
15+
"paths": [
16+
{
17+
"path": "/_sql/async/{id}",
18+
"methods": [
19+
"GET"
20+
],
21+
"parts": {
22+
"id": {
23+
"type": "string",
24+
"description": "The async search ID"
25+
}
26+
}
27+
}
28+
]
29+
},
30+
"params": {
31+
"delimiter": {
32+
"type": "string",
33+
"description": "Separator for CSV results",
34+
"default": ","
35+
},
36+
"format": {
37+
"type": "string",
38+
"description": "Short version of the Accept header, e.g. json, yaml"
39+
},
40+
"keep_alive": {
41+
"type": "time",
42+
"description": "Retention period for the search and its results",
43+
"default": "5d"
44+
},
45+
"wait_for_completion_timeout": {
46+
"type": "time",
47+
"description": "Duration to wait for complete results"
48+
}
49+
}
50+
}
51+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"sql.get_async_status": {
3+
"documentation": {
4+
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-status-api.html",
5+
"description": "Returns the current status of an async SQL search or a stored synchronous SQL search"
6+
},
7+
"stability": "stable",
8+
"visibility": "public",
9+
"headers": {
10+
"accept": [
11+
"application/json"
12+
]
13+
},
14+
"url": {
15+
"paths": [
16+
{
17+
"path": "/_sql/async/status/{id}",
18+
"methods": [
19+
"GET"
20+
],
21+
"parts": {
22+
"id": {
23+
"type": "string",
24+
"description": "The async search ID"
25+
}
26+
}
27+
}
28+
]
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)