sql-search-api.asciidoc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. `allow_partial_search_results`::
  44. (Optional, Boolean) If `true`, returns partial results if there are shard
  45. request timeouts or <<shard-failures,shard failures>>. If `false`, returns an error with no
  46. partial results. Defaults to `false`.
  47. `catalog`::
  48. (Optional, string) Default catalog (cluster) for queries. If unspecified, the
  49. queries execute on the data in the local cluster only.
  50. +
  51. experimental:[] See <<modules-cross-cluster-search,{ccs}>>.
  52. `columnar`::
  53. (Optional, Boolean) If `true`, returns results in a columnar format. Defaults to
  54. `false`. The API only supports this parameter for CBOR, JSON, SMILE, and YAML
  55. responses. See <<sql-rest-columnar>>.
  56. `cursor`::
  57. (Optional, string) <<sql-pagination,Cursor>> used to retrieve a set of paginated
  58. results. If you specify a `cursor`, the API only uses the `columnar` and
  59. `time_zone` request body parameters. It ignores other request body parameters.
  60. [[sql-search-api-fetch-size]]
  61. `fetch_size`::
  62. (Optional, integer) Maximum number of rows to return in the response. Defaults
  63. to `1000`.
  64. [[sql-search-api-field-multi-value-leniency]]
  65. `field_multi_value_leniency`::
  66. (Optional, Boolean) If `false`, the API returns an error for fields containing
  67. <<array,array values>>. If `true`, the API returns the first value from the
  68. array with no guarantee of consistent results. Defaults to `false`.
  69. `filter`::
  70. (Optional, object) <<query-dsl,Query DSL>> used to filter documents for the SQL
  71. search. See <<sql-rest-filtering>>.
  72. `index_include_frozen`::
  73. (Optional, Boolean) If `true`, the search can run on frozen indices. Defaults to
  74. `false`.
  75. `keep_alive`::
  76. (Optional, <<time-units,time value>>) Retention period for an
  77. <<sql-async,async>> or <<sql-store-searches,saved synchronous search>>. Defaults
  78. to `5d` (five days).
  79. `keep_on_completion`::
  80. (Optional, Boolean) If `true`, {es} <<sql-store-searches,stores synchronous
  81. searches>> if you also specify the `wait_for_completion_timeout` parameter. If
  82. `false`, {es} only stores <<sql-async,async searches>> that don't finish before
  83. the `wait_for_completion_timeout`. Defaults to `false`.
  84. `page_timeout`::
  85. (Optional, <<time-units,time value>>) Minimum retention period for the scroll
  86. cursor. After this time period, a <<sql-pagination,pagination request>> might
  87. fail because the scroll cursor is no longer available. Subsequent scroll requests
  88. prolong the lifetime of the scroll cursor by the duration of `page_timeout` in
  89. the scroll request. Defaults to `45s` (45 seconds).
  90. `params`::
  91. (Optional, array) Values for parameters in the `query`. For syntax, see
  92. <<sql-rest-params>>.
  93. `query`::
  94. (Required, object) SQL query to run. For syntax, see <<sql-spec>>.
  95. `request_timeout`::
  96. (Optional, <<time-units,time value>>) Timeout before the request fails. Defaults
  97. to `90s` (90 seconds).
  98. include::{es-repo-dir}/search/search.asciidoc[tag=runtime-mappings-def]
  99. [[sql-search-api-time-zone]]
  100. `time_zone`::
  101. (Optional, string) ISO-8601 time zone ID for the search. Several
  102. <<sql-functions-datetime,SQL date/time functions>> use this time zone. Defaults
  103. to `Z` (UTC).
  104. `wait_for_completion_timeout`::
  105. (Optional, <<time-units,time value>>) Period to wait for complete results.
  106. Defaults to no timeout, meaning the request waits for complete search results.
  107. If the search doesn’t finish within this period, the search becomes
  108. <<sql-async,async>>.
  109. +
  110. To <<sql-store-searches,save a synchronous search>>, you must specify this
  111. parameter and the `keep_on_completion` parameter.
  112. [role="child_attributes"]
  113. [[sql-search-api-response-body]]
  114. ==== {api-response-body-title}
  115. The SQL search API supports <<sql-rest-format,multiple response formats>>. Most
  116. response formats use a tabular layout. JSON responses contain the following
  117. properties:
  118. `id`::
  119. (string) Identifier for the search. This value is only returned for
  120. <<sql-async,async>> and <<sql-store-searches,saved synchronous searches>>. For
  121. CSV, TSV, and TXT responses, this value is returned in the `Async-ID` HTTP
  122. header.
  123. `is_running`::
  124. (Boolean) If `true`, the search is still running. If `false`, the search has
  125. finished. This value is only returned for <<sql-async,async>> and
  126. <<sql-store-searches,saved synchronous searches>>. For CSV, TSV, and TXT
  127. responses, this value is returned in the `Async-partial` HTTP header.
  128. `is_partial`::
  129. (Boolean) If `true`, the response does not contain complete search results. If
  130. `is_partial` is `true` and `is_running` is `true`, the search is still running.
  131. If `is_partial` is `true` but `is_running` is `false`, the results are partial
  132. due to a failure or timeout.
  133. +
  134. This value is only returned for <<sql-async,async>> and
  135. <<sql-store-searches,saved synchronous searches>>. For CSV, TSV, and TXT
  136. responses, this value is returned in the `Async-partial` HTTP header.
  137. `rows`::
  138. (array of arrays)
  139. Values for the search results.
  140. `columns`::
  141. (array of objects)
  142. Column headings for the search results. Each object is a column.
  143. +
  144. .Properties of `columns` objects
  145. [%collapsible%open]
  146. ====
  147. `name`::
  148. (string) Name of the column.
  149. `type`::
  150. (string) Data type for the column.
  151. ====
  152. `cursor`::
  153. (string) <<sql-pagination,Cursor>> for the next set of paginated results. For
  154. CSV, TSV, and TXT responses, this value is returned in the `Cursor` HTTP header.