sql-search-api.asciidoc 5.8 KB

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