esql-query-api.asciidoc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. `include_ccs_metadata`::
  58. (Optional, boolean) If `true`, cross-cluster searches will include metadata about the query
  59. on each cluster. Defaults to `false`. The API only supports this parameter for CBOR, JSON, SMILE,
  60. and YAML responses. See <<ccq-cluster-details>>.
  61. `locale`::
  62. (Optional, string) Returns results (especially dates) formatted per the conventions of the locale.
  63. For syntax, refer to <<esql-locale-param>>.
  64. `params`::
  65. (Optional, array) Values for parameters in the `query`. For syntax, refer to
  66. <<esql-rest-params>>.
  67. `profile`::
  68. (Optional, boolean) If provided and `true` the response will include an extra `profile` object
  69. with information about how the query was executed. It provides insight into the performance
  70. of each part of the query. This is for human debugging as the object's format might change at any time.
  71. Think of this like https://www.postgresql.org/docs/current/sql-explain.html[EXPLAIN ANALYZE] or
  72. https://en.wikipedia.org/wiki/Query_plan[EXPLAIN PLAN].
  73. `query`::
  74. (Required, string) {esql} query to run. For syntax, refer to <<esql-syntax>>.
  75. ifeval::["{release-state}"=="unreleased"]
  76. `table`::
  77. (Optional, object) Named "table" parameters that can be referenced by the <<esql-lookup>> command.
  78. endif::[]
  79. [discrete]
  80. [role="child_attributes"]
  81. [[esql-query-api-response-body]]
  82. ==== {api-response-body-title}
  83. `columns`::
  84. (array of objects)
  85. Column `name` and `type` for each column returned in `values`. Each object is a single column.
  86. `all_columns`::
  87. (array of objects)
  88. Column `name` and `type` for each queried column. Each object is a single column. This is only
  89. returned if `drop_null_columns` is sent with the request.
  90. `values`::
  91. (array of arrays)
  92. Values for the search results.
  93. `_clusters`::
  94. (object)
  95. Metadata about clusters involved in the execution of a cross-cluster query. Only returned (1) for
  96. cross-cluster searches and (2) when `include_ccs_metadata` is sent in the body and set to `true`
  97. and (3) when `format` of the response is set to JSON (the default), CBOR, SMILE, or YAML.
  98. See <<ccq-cluster-details>> for more information.
  99. `profile`::
  100. (object)
  101. Profile describing the execution of the query. Only returned if `profile` was sent in the body.
  102. The object itself is for human debugging and can change at any time. Think of this like
  103. https://www.postgresql.org/docs/current/sql-explain.html[EXPLAIN ANALYZE] or
  104. https://en.wikipedia.org/wiki/Query_plan[EXPLAIN PLAN].