1
0

sql-search-api.asciidoc 6.0 KB

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