esql-query-api.asciidoc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. [[esql-query-api]]
  2. == {esql} query API
  3. ++++
  4. <titleabbrev>{esql} query API</titleabbrev>
  5. ++++
  6. Returns search results for an <<esql,ES|QL ({es} query language)>> query.
  7. [source,console]
  8. ----
  9. POST /_query
  10. {
  11. "query": """
  12. FROM library
  13. | EVAL year = DATE_TRUNC(1 YEARS, release_date)
  14. | STATS MAX(page_count) BY year
  15. | SORT year
  16. | LIMIT 5
  17. """
  18. }
  19. ----
  20. // TEST[setup:library]
  21. [discrete]
  22. [[esql-query-api-request]]
  23. === {api-request-title}
  24. `POST _query`
  25. [discrete]
  26. [[esql-query-api-prereqs]]
  27. === {api-prereq-title}
  28. * If the {es} {security-features} are enabled, you must have the `read`
  29. <<privileges-list-indices,index privilege>> for the data stream, index,
  30. or alias you search.
  31. [discrete]
  32. [[esql-query-api-query-params]]
  33. === {api-query-parms-title}
  34. `delimiter`::
  35. (Optional, string) Separator for CSV results. Defaults to `,`. The API only
  36. supports this parameter for CSV responses.
  37. `format`::
  38. (Optional, string) Format for the response. For valid values, refer to
  39. <<esql-rest-format>>.
  40. +
  41. You can also specify a format using the `Accept` HTTP header. If you specify
  42. both this parameter and the `Accept` HTTP header, this parameter takes
  43. precedence.
  44. [discrete]
  45. [role="child_attributes"]
  46. [[esql-query-api-request-body]]
  47. === {api-request-body-title}
  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 <<esql-rest-columnar>>.
  52. `params`::
  53. (Optional, array) Values for parameters in the `query`. For syntax, refer to
  54. <<esql-rest-params>>.
  55. `query`::
  56. (Required, object) {esql} query to run. For syntax, refer to <<esql-syntax>>.
  57. [[esql-search-api-time-zone]]
  58. `time_zone`::
  59. (Optional, string) ISO-8601 time zone ID for the search. Several {esql}
  60. date/time functions use this time zone. Defaults to `Z` (UTC).
  61. [discrete]
  62. [role="child_attributes"]
  63. [[esql-query-api-response-body]]
  64. === {api-response-body-title}
  65. `columns`::
  66. (array of objects)
  67. Column headings for the search results. Each object is a column.
  68. +
  69. .Properties of `columns` objects
  70. [%collapsible%open]
  71. ====
  72. `name`::
  73. (string) Name of the column.
  74. `type`::
  75. (string) Data type for the column.
  76. ====
  77. `rows`::
  78. (array of arrays)
  79. Values for the search results.