esql-query-api.asciidoc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. [discrete]
  58. [role="child_attributes"]
  59. [[esql-query-api-response-body]]
  60. ==== {api-response-body-title}
  61. `columns`::
  62. (array of objects)
  63. Column headings for the search results. Each object is a column.
  64. +
  65. .Properties of `columns` objects
  66. [%collapsible%open]
  67. =====
  68. `name`::
  69. (string) Name of the column.
  70. `type`::
  71. (string) Data type for the column.
  72. =====
  73. `rows`::
  74. (array of arrays)
  75. Values for the search results.