sql-search-api.asciidoc 5.9 KB

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