esql-query-api.asciidoc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. `drop_null_columns`::
  38. (Optional, boolean) Should columns that are entirely `null` be removed from
  39. the `columns` and `values` portion of the results? Defaults to `false`. If
  40. `true` the the response will include an extra section under the name
  41. `all_columns` which has the name of all columns.
  42. `format`::
  43. (Optional, string) Format for the response. For valid values, refer to
  44. <<esql-rest-format>>.
  45. +
  46. You can also specify a format using the `Accept` HTTP header. If you specify
  47. both this parameter and the `Accept` HTTP header, this parameter takes
  48. precedence.
  49. [discrete]
  50. [role="child_attributes"]
  51. [[esql-query-api-request-body]]
  52. ==== {api-request-body-title}
  53. `columnar`::
  54. (Optional, Boolean) If `true`, returns results in a columnar format. Defaults to
  55. `false`. The API only supports this parameter for CBOR, JSON, SMILE, and YAML
  56. responses. See <<esql-rest-columnar>>.
  57. `params`::
  58. (Optional, array) Values for parameters in the `query`. For syntax, refer to
  59. <<esql-rest-params>>.
  60. `query`::
  61. (Required, object) {esql} query to run. For syntax, refer to <<esql-syntax>>.
  62. [discrete]
  63. [role="child_attributes"]
  64. [[esql-query-api-response-body]]
  65. ==== {api-response-body-title}
  66. `columns`::
  67. (array of objects)
  68. Column `name` and `type` for each column returned in `values`. Each object is a single column.
  69. `all_columns`::
  70. (array of objects)
  71. Column `name` and `type` for each queried column. Each object is a single column. This is only
  72. returned if `drop_null_columns` is sent with the request.
  73. `rows`::
  74. (array of arrays)
  75. Values for the search results.