esql-query-api.asciidoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. [[esql-query-api]]
  2. === {esql} query API
  3. ++++
  4. <titleabbrev>{esql} query API</titleabbrev>
  5. ++++
  6. .New API reference
  7. [sidebar]
  8. --
  9. For the most up-to-date API details, refer to {api-es}/group/endpoint-esql[ES|QL APIs].
  10. --
  11. Returns search results for an <<esql,ES|QL ({es} query language)>> query.
  12. [source,console]
  13. ----
  14. POST /_query
  15. {
  16. "query": """
  17. FROM library
  18. | EVAL year = DATE_TRUNC(1 YEARS, release_date)
  19. | STATS MAX(page_count) BY year
  20. | SORT year
  21. | LIMIT 5
  22. """
  23. }
  24. ----
  25. // TEST[setup:library]
  26. [discrete]
  27. [[esql-query-api-request]]
  28. ==== {api-request-title}
  29. `POST _query`
  30. [discrete]
  31. [[esql-query-api-prereqs]]
  32. ==== {api-prereq-title}
  33. * If the {es} {security-features} are enabled, you must have the `read`
  34. <<privileges-list-indices,index privilege>> for the data stream, index,
  35. or alias you search.
  36. [discrete]
  37. [[esql-query-api-query-params]]
  38. ==== {api-query-parms-title}
  39. `delimiter`::
  40. (Optional, string) Separator for CSV results. Defaults to `,`. The API only
  41. supports this parameter for CSV responses.
  42. `drop_null_columns`::
  43. (Optional, boolean) Should columns that are entirely `null` be removed from
  44. the `columns` and `values` portion of the results? Defaults to `false`. If
  45. `true` the the response will include an extra section under the name
  46. `all_columns` which has the name of all columns.
  47. `format`::
  48. (Optional, string) Format for the response. For valid values, refer to
  49. <<esql-rest-format>>.
  50. +
  51. You can also specify a format using the `Accept` HTTP header. If you specify
  52. both this parameter and the `Accept` HTTP header, this parameter takes
  53. precedence.
  54. `allow_partial_results`::
  55. (Optional, boolean) If `true`, partial results will be returned if there are shard failures, but
  56. the query can continue to execute on other clusters and shards. This defaults to `true`, unless
  57. the cluster setting `esql.query.allow_partial_results` is set to `false`, in which case it also
  58. defaults to `false`.
  59. [discrete]
  60. [role="child_attributes"]
  61. [[esql-query-api-request-body]]
  62. ==== {api-request-body-title}
  63. `columnar`::
  64. (Optional, Boolean) If `true`, returns results in a columnar format. Defaults to
  65. `false`. The API only supports this parameter for CBOR, JSON, SMILE, and YAML
  66. responses. See <<esql-rest-columnar>>.
  67. `include_ccs_metadata`::
  68. (Optional, boolean) If `true`, cross-cluster searches will include metadata about the query
  69. on each cluster. Defaults to `false`. The API only supports this parameter for CBOR, JSON, SMILE,
  70. and YAML responses. See <<ccq-cluster-details>>.
  71. `locale`::
  72. (Optional, string) Returns results (especially dates) formatted per the conventions of the locale.
  73. For syntax, refer to <<esql-locale-param>>.
  74. `params`::
  75. (Optional, array) Values for parameters in the `query`. For syntax, refer to
  76. <<esql-rest-params>>.
  77. `profile`::
  78. (Optional, boolean) If provided and `true` the response will include an extra `profile` object
  79. with information about how the query was executed. It provides insight into the performance
  80. of each part of the query. This is for human debugging as the object's format might change at any time.
  81. Think of this like https://www.postgresql.org/docs/current/sql-explain.html[EXPLAIN ANALYZE] or
  82. https://en.wikipedia.org/wiki/Query_plan[EXPLAIN PLAN].
  83. `query`::
  84. (Required, string) {esql} query to run. For syntax, refer to <<esql-syntax>>.
  85. ifeval::["{release-state}"=="unreleased"]
  86. //`table`::
  87. //(Optional, object) Named "table" parameters that can be referenced by the <<esql-lookup>> command.
  88. endif::[]
  89. [discrete]
  90. [role="child_attributes"]
  91. [[esql-query-api-response-body]]
  92. ==== {api-response-body-title}
  93. `columns`::
  94. (array of objects)
  95. Column `name` and `type` for each column returned in `values`. Each object is a single column.
  96. `all_columns`::
  97. (array of objects)
  98. Column `name` and `type` for each queried column. Each object is a single column. This is only
  99. returned if `drop_null_columns` is sent with the request.
  100. `values`::
  101. (array of arrays)
  102. Values for the search results.
  103. `is_partial`::
  104. (boolean)
  105. Indicates whether the response is partial. Partial responses can happen due to partial shard failures,
  106. failures in remote clusters, or if the async query was stopped by calling the <<esql-async-query-stop-api,async query stop API>>.
  107. `_clusters`::
  108. (object)
  109. Metadata about clusters involved in the execution of a query. This field is present in the response in the following cases:
  110. (1) for cross-cluster searches, when `include_ccs_metadata` is sent in the body and set to `true`;
  111. (2) the result is partial (`is_partial` is `true`) and there are failures on some clusters.
  112. It is only returned if the `format` of the response is set to JSON (the default), CBOR, SMILE, or YAML.
  113. See <<ccq-cluster-details>> for more information.
  114. `profile`::
  115. (object)
  116. Profile describing the execution of the query. Only returned if `profile` was sent in the body.
  117. The object itself is for human debugging and can change at any time. Think of this like
  118. https://www.postgresql.org/docs/current/sql-explain.html[EXPLAIN ANALYZE] or
  119. https://en.wikipedia.org/wiki/Query_plan[EXPLAIN PLAN].