esql-query-api.asciidoc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. "version": "2024.04.01"
  19. }
  20. ----
  21. // TEST[setup:library]
  22. [discrete]
  23. [[esql-query-api-request]]
  24. ==== {api-request-title}
  25. `POST _query`
  26. [discrete]
  27. [[esql-query-api-prereqs]]
  28. ==== {api-prereq-title}
  29. * If the {es} {security-features} are enabled, you must have the `read`
  30. <<privileges-list-indices,index privilege>> for the data stream, index,
  31. or alias you search.
  32. [discrete]
  33. [[esql-query-api-query-params]]
  34. ==== {api-query-parms-title}
  35. `delimiter`::
  36. (Optional, string) Separator for CSV results. Defaults to `,`. The API only
  37. supports this parameter for CSV responses.
  38. `drop_null_columns`::
  39. (Optional, boolean) Should columns that are entirely `null` be removed from
  40. the `columns` and `values` portion of the results? Defaults to `false`. If
  41. `true` the the response will include an extra section under the name
  42. `all_columns` which has the name of all columns.
  43. `format`::
  44. (Optional, string) Format for the response. For valid values, refer to
  45. <<esql-rest-format>>.
  46. +
  47. You can also specify a format using the `Accept` HTTP header. If you specify
  48. both this parameter and the `Accept` HTTP header, this parameter takes
  49. precedence.
  50. [discrete]
  51. [role="child_attributes"]
  52. [[esql-query-api-request-body]]
  53. ==== {api-request-body-title}
  54. `columnar`::
  55. (Optional, Boolean) If `true`, returns results in a columnar format. Defaults to
  56. `false`. The API only supports this parameter for CBOR, JSON, SMILE, and YAML
  57. responses. See <<esql-rest-columnar>>.
  58. `locale`::
  59. (Optional, string) Returns results (especially dates) formatted per the conventions of the locale.
  60. For syntax, refer to <<esql-locale-param>>.
  61. `params`::
  62. (Optional, array) Values for parameters in the `query`. For syntax, refer to
  63. <<esql-rest-params>>.
  64. `query`::
  65. (Required, string) {esql} query to run. For syntax, refer to <<esql-syntax>>.
  66. `version`::
  67. (Required, string) {esql} language version. Can be sent in short or long form, e.g.
  68. `2024.04.01` or `2024.04.01.🚀`. See <<esql-version>> for details.
  69. [discrete]
  70. [role="child_attributes"]
  71. [[esql-query-api-response-body]]
  72. ==== {api-response-body-title}
  73. `columns`::
  74. (array of objects)
  75. Column `name` and `type` for each column returned in `values`. Each object is a single column.
  76. `all_columns`::
  77. (array of objects)
  78. Column `name` and `type` for each queried column. Each object is a single column. This is only
  79. returned if `drop_null_columns` is sent with the request.
  80. `rows`::
  81. (array of arrays)
  82. Values for the search results.