sql-search-api.asciidoc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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>>) Timeout before a
  78. <<sql-pagination,pagination request>> fails. Defaults to `45s` (45 seconds).
  79. `params`::
  80. (Optional, array) Values for parameters in the `query`. For syntax, see
  81. <<sql-rest-params>>.
  82. `query`::
  83. (Required, object) SQL query to run. For syntax, see <<sql-spec>>.
  84. `request_timeout`::
  85. (Optional, <<time-units,time value>>) Timeout before the request fails. Defaults
  86. to `90s` (90 seconds).
  87. include::{es-repo-dir}/search/search.asciidoc[tag=runtime-mappings-def]
  88. [[sql-search-api-time-zone]]
  89. `time_zone`::
  90. (Optional, string) ISO-8601 time zone ID for the search. Several
  91. <<sql-functions-datetime,SQL date/time functions>> use this time zone. Defaults
  92. to `Z` (UTC).
  93. `wait_for_completion_timeout`::
  94. (Optional, <<time-units,time value>>) Period to wait for complete results.
  95. Defaults to no timeout, meaning the request waits for complete search results.
  96. If the search doesn’t finish within this period, the search becomes
  97. <<sql-async,async>>.
  98. +
  99. To <<sql-store-searches,save a synchronous search>>, you must specify this
  100. parameter and the `keep_on_completion` parameter.
  101. [role="child_attributes"]
  102. [[sql-search-api-response-body]]
  103. ==== {api-response-body-title}
  104. The SQL search API supports <<sql-rest-format,multiple response formats>>. Most
  105. response formats use a tabular layout. JSON responses contain the following
  106. properties:
  107. `id`::
  108. (string) Identifier for the search. This value is only returned for
  109. <<sql-async,async>> and <<sql-store-searches,saved synchronous searches>>. For
  110. CSV, TSV, and TXT responses, this value is returned in the `Async-ID` HTTP
  111. header.
  112. `is_running`::
  113. (Boolean) If `true`, the search is still running. If `false`, the search has
  114. finished. This value is only returned for <<sql-async,async>> and
  115. <<sql-store-searches,saved synchronous searches>>. For CSV, TSV, and TXT
  116. responses, this value is returned in the `Async-partial` HTTP header.
  117. `is_partial`::
  118. (Boolean) If `true`, the response does not contain complete search results. If
  119. `is_partial` is `true` and `is_running` is `true`, the search is still running.
  120. If `is_partial` is `true` but `is_running` is `false`, the results are partial
  121. due to a failure or timeout.
  122. +
  123. This value is only returned for <<sql-async,async>> and
  124. <<sql-store-searches,saved synchronous searches>>. For CSV, TSV, and TXT
  125. responses, this value is returned in the `Async-partial` HTTP header.
  126. `rows`::
  127. (array of arrays)
  128. Values for the search results.
  129. `columns`::
  130. (array of objects)
  131. Column headings for the search results. Each object is a column.
  132. +
  133. .Properties of `columns` objects
  134. [%collapsible%open]
  135. ====
  136. `name`::
  137. (string) Name of the column.
  138. `type`::
  139. (string) Data type for the column.
  140. ====
  141. `cursor`::
  142. (string) <<sql-pagination,Cursor>> for the next set of paginated results. For
  143. CSV, TSV, and TXT responses, this value is returned in the `Cursor` HTTP header.